首页 > 解决方案 > Elasticsearch bool must query

问题描述

I am trying to write a Elasticsearch bool query. I am having an issue querying an field (DATE) using bool must query. Elastic search data look like so:

{
    "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 like that:

{
"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
      }
    }

}

The query is not working. Any idea please?

标签: elasticsearch

解决方案


试试下面的代码,

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

推荐阅读