在ElasticSearch中,如何搜索一大堆关键词

问题描述 投票:0回答:2

我已经在加载了 ElasticSearch 库的 python 中构建了以下查询。 我想继续扩展下面的列表,以便我可以找到列表中相应的数据。
如何将“列表”传递到 ElasticSearch 查询中,以便以后在需要向搜索列表中添加更多(如数百个)时可以继续扩展“列表”?

list = ["123","234","456"]

query_all = {
           "query": {
                    "bool":{
                           "must":[
                                  {"match": {"orderData.orderId.id.keyword" : list}},                                    
                                  ]
                            }
                     }
              }
python list elasticsearch variables arraylist
2个回答
0
投票

可能您正在寻找术语查询

{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "orderData.orderId.id.keyword": list
          }
        }
      ]
    }
  }
}

0
投票

如果文档分数对您的需求并不重要,您可以使用 Elasticsearch 中的“过滤”功能而不是“必须”。

过滤器通常比“must”子句更快,因为它们不参与评分计算,从而加快查询执行速度。

{
  "query": {
    "bool": {
      "fi": [
        {
          "terms": {
            "orderData.orderId.id.keyword": list
          }
        }
      ]
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.