Created
October 12, 2011 12:46
-
-
Save frazerh/1281147 to your computer and use it in GitHub Desktop.
Elasticsearch text phrase prefix search with expansion
This file contains hidden or 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
From Docs: max_expansions parameter that can control to how many prefixes the last term will be expanded. It is highly recommended to set it to an acceptable value to control the execution time of the query. | |
curl -X DELETE localhost:9200/cities | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Gabriel" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Gwann" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Carlos" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Cristobal" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Clemente" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Diego" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Dimas" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Douglas" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Francisco" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Felipe" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Francisco De Dos Rios" }' | |
curl -X POST "http://localhost:9200/cities/city" -d '{ "city" : "San Fidel" }' | |
---------------------------------------------------------------------------------------------- | |
curl -XGET 'http://localhost:9200/cities/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"text_phrase_prefix" : { | |
"city" : { | |
"query" : "San f", | |
"max_expansions" : 0 | |
} | |
} | |
} | |
}' | |
{ | |
"took" : 33, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 3, | |
"max_score" : 1.3646637, | |
"hits" : [ { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "461gnzgbQX-RzCyrOFlEgQ", | |
"_score" : 1.3646637, "_source" : { "city" : "San Francisco De Dos Rios" } | |
}, { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "-Sw_PeYJQg2nlyVpJYknvA", | |
"_score" : 1.3236144, "_source" : { "city" : "San Felipe" } | |
}, { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "rvN_BPllQie-xL-xtkHA0g", | |
"_score" : 0.9965843, "_source" : { "city" : "San Francisco" } | |
} ] | |
} | |
3 hits, San Fidel not returned, not sure why | |
---------------------------------------------------------------------------------------------- | |
curl -XGET 'http://localhost:9200/cities/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"text_phrase_prefix" : { | |
"city" : { | |
"query" : "San f", | |
"max_expansions" : 2 | |
} | |
} | |
} | |
}' | |
{ | |
"took" : 43, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 4, | |
"max_score" : 2.2020302, | |
"hits" : [ { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "-Sw_PeYJQg2nlyVpJYknvA", | |
"_score" : 2.2020302, "_source" : { "city" : "San Felipe" } | |
}, { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "WMbYShc5TWa-TjQ0rjL5Vg", | |
"_score" : 2.2020302, "_source" : { "city" : "San Fidel" } | |
}, { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "461gnzgbQX-RzCyrOFlEgQ", | |
"_score" : 1.3646637, "_source" : { "city" : "San Francisco De Dos Rios" } | |
}, { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "rvN_BPllQie-xL-xtkHA0g", | |
"_score" : 0.9965843, "_source" : { "city" : "San Francisco" } | |
} ] | |
} | |
4 hits returned | |
---------------------------------------------------------------------------------------------- | |
curl -XGET 'http://localhost:9200/cities/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"text_phrase_prefix" : { | |
"city" : { | |
"query" : "San d", | |
"max_expansions" : 0 | |
} | |
} | |
} | |
}' | |
{ | |
"took" : 2, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 0, | |
"max_score" : null, | |
"hits" : [ ] | |
} | |
0 returned, should this be? | |
---------------------------------------------------------------------------------------------- | |
curl -XGET 'http://localhost:9200/cities/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"text_phrase_prefix" : { | |
"city" : { | |
"query" : "San d", | |
"max_expansions" : 2 | |
} | |
} | |
} | |
}' | |
{ | |
"took" : 22, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : 3.3574967, | |
"hits" : [ { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "DpbmhNrTRWyPQZlNkDL-_A", | |
"_score" : 3.3574967, "_source" : { "city" : "San Diego" } | |
} ] | |
} | |
1 hit? | |
---------------------------------------------------------------------------------------------- | |
curl -XGET 'http://localhost:9200/cities/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"text_phrase_prefix" : { | |
"city" : { | |
"query" : "San d", | |
"max_expansions" : 3 | |
} | |
} | |
} | |
}' | |
{ | |
"took" : 1, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 2, | |
"max_score" : 4.7654734, | |
"hits" : [ { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "DpbmhNrTRWyPQZlNkDL-_A", | |
"_score" : 4.7654734, "_source" : { "city" : "San Diego" } | |
}, { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "ahHdrzDhTbSad_qShrbN7g", | |
"_score" : 4.7654734, "_source" : { "city" : "San Dimas" } | |
} ] | |
} | |
---------------------------------------------------------------------------------------------- | |
curl -XGET 'http://localhost:9200/cities/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"text_phrase_prefix" : { | |
"city" : { | |
"query" : "San d", | |
"max_expansions" : 5 | |
} | |
} | |
} | |
}' | |
{ | |
"took" : 20, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 3, | |
"max_score" : 7.581427, | |
"hits" : [ { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "DpbmhNrTRWyPQZlNkDL-_A", | |
"_score" : 7.581427, "_source" : { "city" : "San Diego" } | |
}, { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "ahHdrzDhTbSad_qShrbN7g", | |
"_score" : 7.581427, "_source" : { "city" : "San Dimas" } | |
}, { | |
"_index" : "cities", | |
"_type" : "city", | |
"_id" : "_hEbRStmSIeI407ev9txeg", | |
"_score" : 7.581427, "_source" : { "city" : "San Douglas" } | |
} ] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how much the value of
number_of_shards
is setting to?