繁体   English   中英

如何在Elasticsearch中查询多个字段?

[英]How to query on multiple fields in elasticsearch?

我试过多字段查询,它工作正常。 但是我想知道在Elasticsearch中通常使用哪些其他选项来查询多个字段?

具有多个术语的结构化查询,用于查找确切值,与SQL相同

https://www.elastic.co/guide/zh-CN/elasticsearch/guide/current/_finding_multiple_exact_values.html

"bool" : {
                    "must" : [
                        { "term" : { "tags" : "search" } }, 
                        { "term" : { "tag_count" : 1 } } 
                    ]
                }

例如,考虑以下sql查询,

SELECT product
FROM   products
WHERE  (price = 20 OR productID = "XHDK-A-1293-#fJ3")
  AND  (price != 30)

在这些情况下,您将需要布尔过滤器。 这是一个复合过滤器,它接受其他过滤器作为参数,将它们组合成各种布尔组合。

查询DSL是

GET /my_store/products/_search
{
   "query" : {
      "filtered" : { 
         "filter" : {
            "bool" : {
              "should" : [
                 { "term" : {"price" : 20}}, 
                 { "term" : {"productID" : "XHDK-A-1293-#fJ3"}} 
              ],
              "must_not" : {
                 "term" : {"price" : 30} 
              }
           }
         }
      }
   }
}

请点击以下链接获取文档https://www.elastic.co/guide/zh-CN/elasticsearch/guide/current/combining-filters.html

暂无
暂无

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

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