简体   繁体   English

弹性搜索:一个查询中的多词搜索

[英]Elastic Search: Multiple term search in one query

New to ElasticSearch. ElasticSearch 的新手。

I have documents under an index : myindex in Elastic search with mappings: http://host:port/myindex/_mapping我在index下有文档:带有映射的弹性搜索中的myindexhttp://host:port/myindex/_mapping

{
"mappings":{
   "properties": {
        "en_US":  {
             "type": "keyword"
                  }
                 }
          }
}

Let's say my 3 documents look like this:假设我的 3 个文件如下所示:

{
"product": "p1",
"subproduct": "p1.1"
}

{
"product": "p1",
"subproduct": "p1.2"
}

{
"product": "p2",
"subproduct": "p2.1"
}

Now, I am querying using for single subproduct p1.1 with product p1 as below and it's working fine:现在,我正在查询用于单个子产品p1.1和产品p1如下,它工作正常:

POST: http://host:port/myindex/_search POST: http://host:port/myindex/_search

{
  "query": {
    "bool" : {
      "must" : {
        "term" : { "product" : "p1" }
      },
      "filter": {
        "term" : { "subproduct" : "p1.1" }
      }
    }
  }
}

My question is : How I can query for 2 or more subproducts in one _search query, like suproducts p1.1 and p1.2 under product p1 ?我的问题是:我怎么能在一个_search查询查询2级或更多的子产品,像suproducts p1.1p1.2下产品p1 Query should return list of all subproduct p1.1 and subproduct p1.2 with p1 product.查询应返回的所有子产品的列表p1.1和子产品p1.2p1产品。

Simply change the term -query in your filter-clause to a terms -query and search for multiple terms.只需将改变term的过滤器子句中-查询到terms -查询和搜索多个方面。

{
  "query": {
    "bool" : {
      "must" : {
        "term" : { "product" : "p1" }
      },
      "filter": {
        "terms" : { "subproduct" : ["p1.1", "p1.2"] }
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM