elasticsearch - 组合 Elasticsearch 查询

标签 elasticsearch

我有以下两个查询:

GET places/_search
{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "should": [
            {
              "term": {
                "approved": false
              }
            }
          ]
        }
      }
    }
  }
}

GET places/_search
{
  "query": {
    "filtered": {
      "filter": {
        "geo_bounding_box": {
          "loc": {
            "top_left": "54.6152065515344, -6.09334913041994",
            "bottom_right": "54.5754258987271, -5.76633420732423"
          }
        }
      }
    }
  }
}

两者都工作正常,但是我在合并查询时遇到问题,并且想知道是否有人可以提供帮助。基本上,我想检索指定边界框内所有项目,其中“approved”属性为false。

最佳答案

您可以保留filtered查询并像这样在bool/must过滤器中合并两个条件

curl -XPOST localhost:9200/places/_search -d '{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "approved": false
              }
            },
            {
              "geo_bounding_box": {
                "loc": {
                  "top_left": "54.6152065515344, -6.09334913041994",
                  "bottom_right": "54.5754258987271, -5.76633420732423"
                }
              }
            }
          ]
        }
      }
    }
  }
}'

关于elasticsearch - 组合 Elasticsearch 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31897546/

相关文章:

javascript - 如何使用elasticsearch javascript库中的search_type

elasticsearch - 嵌套对象中多个字段上的聚合在 Elasticsearch 1.7x中不起作用?

solr - 太阳黑子和轮胎 gem 的区别

testing - 通过文件初始化 Elasticsearch 数据库

node.js - Elasticsearch找不到最近插入的数据

elasticsearch - 如何在Elasticsearch中按 “nested”哈希值排序

docker - docker Elasticsearch 5.6.10如何删除用户名和密码

django - 搜索结果因分页而失败

security - Docker上的Elasticsearch 1.7.3和Shield

apache-spark - 为什么在提交到 YARN 集群时,elasticsearch-spark 5.5.0 会因 AbstractMethodError 而失败?