elasticsearch - 如何在Elasticsearch中使用嵌套过滤器?

标签 elasticsearch

我有一组文章。我想过滤tagshost

例如,我希望所有标有“新闻”或“体育”并且“主机”设置为“cnn.com”或“bbc.com”的文章。

我试图创建此嵌套的 bool(boolean) 过滤器,但这没有用。它还返回其他主机的文章。
有什么建议么?

GET _search
{
    "query": {
      "filtered": {
        "query": {
          "match_all": {}
        },
        "filter": {
          "bool": {
            "should": [
              // Match one or more of these tags.
              { "term" : { "tags" : "sport"} },
              { "term" : { "tags" : "news"} },
              { "bool": { 
                // Only from one of these hosts.
                "should": [
                  { "term": { "host": "bbc.com" } },
                  { "term": { "host": "cnn.com" } }
                ]
              }}
            ]
          }
        }
      }
    }
}

最佳答案

像这样嵌套查询是可行的。 :-)

GET _search
{
    "query": {
      "filtered": {
        "query": {
          "match_all": {}
        },
        "filter": {
          "bool": {
            "must": [

              { "bool": {
                "should": [
                  { "term" : { "tags" : "sport"} },
                  { "term" : { "tags" : "news"} }
                ]
              }},

              { "bool": { 
                "should": [
                  { "term": { "host": "bbc.com" } },
                  { "term": { "host": "cnn.com" } }
                ]
              }}
            ]
          }
        }
      }
    }
}

关于elasticsearch - 如何在Elasticsearch中使用嵌套过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32202793/

相关文章:

performance - 在 Elasticsearch 中搜索时是否有办法关闭评分以提高性能?

mysql - ElasticSearch如何与Mysql集成

elasticsearch - 包含空值后, Elasticsearch 更新失败

用于 Elasticsearch 的 C++ api

php - 使用AND和OR的Elasticsearch NOT bool 运算

elasticsearch - 在Elasticsearch中检索记录ID

java - 如何使用elasticsearch java api连接位于不同服务器上的多个节点?

json - 在Kibana中创建地理位置

elasticsearch - 使用logstash将数据从elasticsearch中获取到csv文件

Elasticsearch:路径 [messages] 下的嵌套对象不是嵌套类型