在日期字段上以 mm-yyyy 格式搜索的 Elasticsearch 查询

Elasticsearch query to search with mm-yyyy format on date field

我想在 yyyy-dd-mm 格式的日期字段上查询类似 03-2015 的 elasticsearch。

我这样试过,但它没有worked.Its没有给出任何错误,它返回了 0 条记录

curl -XPOST "http://localhost:9200/myindex/mytype/_search?pretty" -d '{
"query": {
    "bool": {
        "must": [
            {
                "range": {
                    "deliverydate": {
                        "gte": "03-2015",
                        "lte": "03-2015",
                        "format": "mm-yyyy" 
                    }
                }
            }

        ]
    }
}

} '

我的示例文档是这个

{
"took": 38,
"timed_out": false,
"_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
},
"hits": {
    "total": 10,
    "max_score": 1,
    "hits": [
        {
            "_index": "myindex",
            "_type": "mytype",
            "_id": "33924",
            "_score": 1,
            "_source": {
                "id": 33924,
                "deliverydate": "2015-03-14",
                "name":"New test order"
            }
        }
        ]
    }

}

谁能帮我解决这个问题。这是对 elasticsearch 数据的有效搜索吗?

你的格式不正确(MM而不是mm),应该是

curl -XPOST "http://localhost:9200/myindex/mytype/_search?pretty" -d '{
"query": {
    "bool": {
        "must": [
            {
                "range": {
                    "deliverydate": {
                        "gte": "03-2015",
                        "lte": "04-2015",
                        "format": "MM-yyyy" 
                    }
                }
            }

        ]
    }
}}'