Skip to content

Instantly share code, notes, and snippets.

@lukas-vlcek
Created October 14, 2013 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukas-vlcek/6972058 to your computer and use it in GitHub Desktop.
Save lukas-vlcek/6972058 to your computer and use it in GitHub Desktop.
Testing search time analyzer. This works.
#!/bin/sh
echo "Elasticsearch version and build:"
curl localhost:9200; echo; echo;
echo "Delete index"
curl -X DELETE 'localhost:9200/i'; echo; echo;
echo "Create index with analysis and mappings"
curl -X PUT 'localhost:9200/i' -d '{
"settings" : {
"analysis" : {
"analyzer" : {
"index_time" : {
"type" : "custom",
"tokenizer" : "standard"
},
"search_time" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : ["lowercase"]
}
}
}}},
"mappings" : {
"t" : {
"properties" : {
"text" : {
type" : "string",
"index_analyzer" : "index_time",
"search_analyzer" : "search_time"
}}}}}'; echo; echo;
# Wait for all the index shards to be allocated
curl -s -X GET 'http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=5s' > /dev/null
echo "Testing analysers: both cases should yield the same lowercased 'hello' token"
echo ===========================
echo "'index_time' analyzer output for query 'hello'"
curl -X POST 'localhost:9200/i/_analyze?analyzer=index_time&format=text&text=hello'; echo;
echo "'serch_time' analyzer output for query 'HELLO'"
curl -X POST 'localhost:9200/i/_analyze?analyzer=search_time&format=text&text=HELLO'; echo; echo;
echo "Index simple data: 'hello'"
curl -X POST 'localhost:9200/i/t' -d '{
"text" : "hello"
}'; echo; echo;
echo "Refresh Lucene reader"; curl -X POST 'localhost:9200/i/_refresh'; echo; echo;
echo "Testing search"
echo ===========================
echo "1) query_string: 'HELLO' - no analyzer specified";
curl -X GET 'localhost:9200/_search' -d '{"query":{"query_string":{"query":"HELLO","default_field":"text"}}}'; echo; echo;
echo "2) query_string: 'HELLO' - specified the same analyzer that is in mappings > search_analyzer";
curl -X GET 'localhost:9200/_search' -d '{"query":{"query_string":{"query":"HELLO","default_field":"text","analyzer":"search_time"}}}'; echo; echo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment