繁体   English   中英

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

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

ElasticSearch 的新手。

我在index下有文档:带有映射的弹性搜索中的myindexhttp://host:port/myindex/_mapping

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

假设我的 3 个文件如下所示:

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

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

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

现在,我正在查询用于单个子产品p1.1和产品p1如下,它工作正常:

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

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

我的问题是:我怎么能在一个_search查询查询2级或更多的子产品,像suproducts p1.1p1.2下产品p1 查询应返回的所有子产品的列表p1.1和子产品p1.2p1产品。

只需将改变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