【问题标题】:Geo, Date, and string matching elasticsearch query地理、日期和字符串匹配弹性搜索查询
【发布时间】:2022-01-10 11:00:43
【问题描述】:

我有一个名为 tweets 的弹性搜索索引, 我正在尝试按地理距离、日期和可能传递的可选字符串来过滤这些推文。这个查询应该如何满足我的要求

       "query":{
          "bool": {
             "must": [
                {
                   "term": {
                      "text": "ew"
                   }
                },
                {
                   "range": {
                      "date": {
                         "gte": "2009-05-31T02:30:45",
                         "lt": "now"
                      }
                   }
                },
                {
                   "filter": {
                      "geo_distance": {
                         "distance": "12km",
                         "pin.location": [-70, 40]
                      }
                   }
                }
              ]
           }
     }

提前致谢

【问题讨论】:

  • 不确定这里的问题是什么?

标签: elasticsearch kibana


【解决方案1】:

您可以使用filter and should clause的组合来达到您需要的效果。

filter的用法类似于逻辑AND运算符,忽略查询的分数,should类似于逻辑OR运算符。

试试下面这个查询:

{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "date": {
              "gte": "2009-05-31T02:30:45",
              "lt": "now"
            }
          }
        },
        {
          "geo_distance": {
            "distance": "12km",
            "pin.location": [
              -70,
              40
            ]
          }
        }
      ],
      "should": {
        "bool": {
          "filter": {
            "term": {
              "text": "ew"
            }
          }
        }
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-10
    相关资源
    最近更新 更多