在Elasticsearch中合并单独的查询 [英] Combine separate queries in elasticsearch

查看:109
本文介绍了在Elasticsearch中合并单独的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个搜索词"86746184549"和"3302093809".我正在执行两个单独的术语查询,以获取与每个ID匹配的一个文档.

I have two search terms "86746184549" and "3302093809". I am executing two separate term queries to fetch one document matching each of the ids.

"size":1,
"query":{
  "term":{
    "from_user_id": "86746184549"
  }

}

"size":1,
"query":{
  "term":{
    "from_user_id": "3302093809"
  }

}

是否有一种方法可以将这两个查询组合在一起,类似于我们在方面中所做的事情.

Is there are a way to combine these 2 queries, something similar to what we do in facets.

 {
    "facets":{
      "facet_1":{

       },
      "facet_2":{

       },
      "facet_3":{

       }  
    }
 }

我认为术语查询之所以可以在这里工作,是因为不会返回包含不同的from_user_id字段的文档.

I don't think the terms query will work here because, that wont return documents containing distinct from_user_id field.

我想合并查询的原因是,例如,如果我有100个这样的字词,那么我将打100个电话!!到Elasticsearch服务器.

The reason I want to combine the queries is because, say if I have 100 such terms then I will be making 100 calls!! to the elasticsearch server.

推荐答案

听起来您正在寻找 Field Collapsing/Combining (字段折叠/合并),这是尚未实现的Elasticsearch广受欢迎的功能.同时,您可以使用多重搜索将多个字词请求合并为一个.

It sounds like you are looking for Field Collapsing/Combining, which is highly sought-after feature of elasticsearch that's not implemented yet. Meanwhile, you can use Multi Search to combine several term requests into one.

这篇关于在Elasticsearch中合并单独的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆