【问题标题】:Elasticsearch bool must queryElasticsearch bool 必须查询
【发布时间】:2019-07-03 12:01:06
【问题描述】:

我正在尝试编写 Elasticsearch 布尔查询。我在使用 bool must query 查询字段 (DATE) 时遇到问题。 弹性搜索数据如下所示:

{
    "took": 5,
    "timed_out": false,
    "_shards": {
        "total": 15,
        "successful": 15,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 11.519888,
        "hits": [
            {
                "_index": "test-2019.06.27",
                "_type": "test",
                "_id": "pa6gmGsByDlvLvAyiRF-",
                "_score": 11.519888,
                "_source": {
                    "DATE": "01/06/19"
                }
            }
        ]
    }
}

这样的 Elasticsearch 查询:

{
"query": 
    {
      "bool" : {
        "must" : [
          {
            "match" : {
              "DATE" : {
                "query" : "01/06/19",
                "operator" : "AND",
                "prefix_length" : 0,
                "max_expansions" : 50,
                "fuzzy_transpositions" : true,
                "lenient" : false,
                "zero_terms_query" : "NONE",
                "auto_generate_synonyms_phrase_query" : true,
                "boost" : 1.0
              }
            }
          }
        ],
        "adjust_pure_negative" : true,
        "boost" : 1.0
      }
    }

}

查询不工作。 请问有什么办法吗?

【问题讨论】:

  • 你能分享你的映射细节吗?只需执行GET test-2019.06.27/_mapping 并更新上述问题中的响应即可。

标签: elasticsearch


【解决方案1】:

对于日期类型的查询,我曾经写过 Range 查询。

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

【讨论】:

    【解决方案2】:

    试试下面的代码,

    {
        "query": {
            "range" : {
                "DATE" : {
                    "gte" : "now-1d/d",
                    "lt" :  "now/d"
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      相关资源
      最近更新 更多