简体   繁体   English

查询上下文是否在 elasticsearch 中的过滤上下文之前评估? 如何确定评价顺序?

[英]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.

相关问题 如何确定何时计算表达式? - How can I determine when an expression is evaluated? Elasticsearch 查询通过重复使用的术语查询过滤器加快速度 - Elasticsearch query speed up with repeated used terms query filter 使用过滤器,查询或两者结合来优化Elasticsearch查询 - optimize elasticsearch query using filter, query or mix of both 如何在 uiautomator 测试用例中获取上下文? - How to get context in uiautomator test case? 使用Linq2Sql上下文强制立即执行IEnumerable查询 - Force immediate execution of IEnumerable query using Linq2Sql context 如何在MVP模式中将上下文传递给存储库 - How to pass context to repository in MVP pattern 上下文切换在Linux中需要多长时间? - How long does a context switch take in Linux? CoreData - 如何使用NSPrivateQueueConcurrencyType使用临时上下文执行NSFetchRequest? - CoreData - How to do NSFetchRequest with temporary context with NSPrivateQueueConcurrencyType? 在这种情况下,php switch case 或数据库查询之间哪个更快 - Which is faster between php switch case or database query in this context Django auth上下文处理器:不为每个请求查询用户 - Django auth context processor: not to query for user for each request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM