[英]Is query context evaluated before filter context in elasticsearch? How to determine the order of evaluation?
I am using the below query:我正在使用以下查询:
GET customer/doc/_search?routing=123
{
"query": {
"bool": {
"filter": [
{
"term": {
"location": "Delhi"
}
}
],
"should": [
{
"match_phrase_prefix": {
"phone": {
"query": "650",
"max_expansions": 100
}
}
}
]
}
}
}
The problem is my search on phone isn't working anymore.问题是我在手机上的搜索不再起作用了。 It used to work fine when I had less data, now every shard has data for multiple locations.当我的数据较少时,它曾经可以正常工作,现在每个分片都有多个位置的数据。 Search on phone now requires me to type in 6 or 7 characters at times.现在在手机上搜索需要我有时输入 6 或 7 个字符。 (There may be matching phone numbers that have different location but are on this shard) (可能有匹配的电话号码具有不同的位置但在此分片上)
This is due to max_expansions I am guessing.这是由于我猜测的 max_expansions 。 When I increase it to 500 it does return me search results (not all), but the query becomes slow.当我将其增加到 500 时,它确实会返回我的搜索结果(不是全部),但查询会变慢。
Isn't there a way to force es to apply filter first (and restrict the dataset) and then apply the should clause, so that I get the matching results even with small value of max_expansions?有没有办法强制es先应用过滤器(并限制数据集)然后应用should子句,这样即使max_expansions的值很小我也能得到匹配的结果?
Any help is appreciated.任何帮助表示赞赏。
It is due to max_expansions.这是由于 max_expansions。 Restricting dataset is not exactly what you may want to do ( Thats also not very straight forward - you may have to use some script which will in turn slowdown query).限制数据集并不是您可能想要做的(这也不是很直接 - 您可能必须使用一些脚本,这反过来会减慢查询速度)。
When you query for a wildcard expression, Lucene expands the wildcard expression into set of actual terms in your inverted index term dictionary.当您查询通配符表达式时,Lucene 将通配符表达式扩展为倒排索引术语字典中的一组实际术语。 Now, when you restrict the term expansion to 500 - it might miss a few.现在,当您将术语扩展限制为 500 时 - 它可能会遗漏一些。
I would consider using prefixes during indexing phase.我会考虑在索引阶段使用前缀。 Prefixes helps to avoid the costly expansion in runtime phase.前缀有助于避免在运行阶段进行代价高昂的扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.