Created
December 14, 2015 16:35
-
-
Save eemp/8bb18d566a57295dab96 to your computer and use it in GitHub Desktop.
Phrase Query, Analyzers, and Stackoverflow Post (http://stackoverflow.com/questions/34264406/whole-word-search-in-elasticsearch)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start clean - hope you don't have a test index you need!!! | |
curl -XDELETE localhost:9200/test | |
curl -XPUT localhost:9200/test | |
printf "\nCreated a new test index...\n" | |
curl -XPUT localhost:9200/test/snowball-mapping/_mapping -d '{ | |
"snowball-mapping" : { | |
"properties" : { | |
"text" : { | |
"type" : "string", | |
"analyzer" : "snowball" | |
} | |
} | |
} | |
}' | |
curl -XGET localhost:9200/test/snowball-mapping/_mapping | python -m json.tool | |
# create 2 documents with "the test" phrase and 1 document with "the testing" phrase | |
## refresh will ensure they can be searched right away | |
curl -XPUT localhost:9200/test/snowball-mapping/1?refresh=1 -d '{ | |
"text" : "this is the test" | |
}' | |
printf "\nCreated document 1 ('this is the test')...\n" | |
curl -XPUT localhost:9200/test/snowball-mapping/2?refresh=1 -d '{ | |
"text" : "the test\non the newline" | |
}' | |
printf "\nCreated document 1 ('the test\nonthe newline')...\n" | |
curl -XPUT localhost:9200/test/snowball-mapping/3?refresh=1 -d '{ | |
"text" : "this is the testing server" | |
}' | |
printf "\nCreated document 1 ('this is the testing server')...\n" | |
curl -XPOST localhost:9200/test/snowball-mapping/_search -d '{ | |
"query" : { | |
"match_phrase" : { | |
"text" : "the testing" | |
} | |
} | |
}' | python -m json.tool | |
curl -XPOST localhost:9200/test/snowball-mapping/_search -d '{ | |
"query" : { | |
"match_phrase" : { | |
"text" : "the test" | |
} | |
} | |
}' | python -m json.tool | |
# cleanup | |
curl -XDELETE localhost:9200/test | |
printf "\nRemoved the test index...\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start clean - hope you don't have a test index you need!!! | |
curl -XDELETE localhost:9200/test | |
curl -XPUT localhost:9200/test | |
printf "\nCreated a new test index...\n" | |
# curl -XPUT localhost:9200/test/standard-mapping/_mapping -d @standard-mapping.json | |
# create 2 documents with "the test" phrase and 1 document with "the testing" phrase | |
## refresh will ensure they can be searched right away | |
curl -XPUT localhost:9200/test/standard-mapping/1?refresh=1 -d '{ | |
"text" : "this is the test" | |
}' | |
printf "\nCreated document 1 ('this is the test')...\n" | |
curl -XPUT localhost:9200/test/standard-mapping/2?refresh=1 -d '{ | |
"text" : "the test\non the newline" | |
}' | |
printf "\nCreated document 1 ('the test\nonthe newline')...\n" | |
curl -XPUT localhost:9200/test/standard-mapping/3?refresh=1 -d '{ | |
"text" : "this is the testing server" | |
}' | |
printf "\nCreated document 1 ('this is the testing server')...\n" | |
curl -XPOST localhost:9200/test/standard-mapping/_search -d '{ | |
"query" : { | |
"match_phrase" : { | |
"text" : "the testing" | |
} | |
} | |
}' | python -m json.tool | |
curl -XPOST localhost:9200/test/standard-mapping/_search -d '{ | |
"query" : { | |
"match_phrase" : { | |
"text" : "the test" | |
} | |
} | |
}' | python -m json.tool | |
# cleanup | |
curl -XDELETE localhost:9200/test | |
printf "\nRemoved the test index...\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment