【问题标题】:Elastic Search Bool Query for multiple fields多个字段的弹性搜索布尔查询
【发布时间】:2020-06-01 15:36:47
【问题描述】:

我有如下索引映射:

请求

|-> tilte 
|-> countryCode
|-> isOpen
|-> location
|-> date

我想同时进行 bool 和 geoquery 获取在同一个国家和我附近的文档,isOpen 我已经尝试了以下但总是我得到一个空的 hits 对象。

{   "from" : 5,
    "size": 5,
    "query": {
        "bool" : {
            "must" : [
                {"match" : {"countryCode": "US"}},
                {"match": {"isOpen": true }}
            ],
            "filter" : {
                "geo_distance" : {
                    "distance" : "150km",
                    "location" : {
                        "lat" : 1111111111,
                        "lon" : 3333333333
                        }
                }
            }
        }
    },

    "sort": [ { "date" : {"order" : "desc"} } ]
 }

回应

{
    "took": 8,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    }
}

即使我确定有很多文档与查询匹配,但我无法得到它。有谁可以帮忙?

【问题讨论】:

    标签: elasticsearch elastic-stack elasticsearch-5


    【解决方案1】:

    我将从将from 的值从 5 更改为 0 开始。接下来我将检查索引定义 - 您确定可以以您使用的方式搜索每个字段吗?你能显示准确的索引定义(映射)并显示来自 Elastic 的示例项目吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      相关资源
      最近更新 更多