filtering by date in elasticsearch

前端 未结 1 1570
后悔当初
后悔当初 2020-12-14 17:32

I\'m Trying to search for all the items who have a field of date inside a range, and it fails (returns no results)

The query:

{
  \"query\": {
    \"         


        
相关标签:
1条回答
  • 2020-12-14 18:32

    Seems to be working fine to me:

    curl -XPUT localhost:9200/test -d '{
        "settings": {
            "index.number_of_shards": 1,
            "index.number_of_replicas": 0
        },
        "mappings": {
            "doc": {
                "_timestamp": {
                    "enabled": "true"
                },
                "properties": {
                    "cards": {
                        "type": "integer"
                    },
                    "last_updated": {
                        "type": "date",
                        "format": "yyyy-MM-dd HH:mm:ss"
                    }
                }
            }
        }
    }
    '
    curl -XPOST localhost:9200/test/doc/1 -d '{
        "last_updated": "2012-01-01 12:13:14"
    }
    '
    curl -XPOST localhost:9200/test/doc/2 -d '{
        "last_updated": "2013-02-02 01:02:03"
    }
    '
    curl -X POST 'http://localhost:9200/test/_refresh'
    echo
    curl -X GET 'http://localhost:9200/test/doc/_search?pretty' -d '{
        "query": {
            "filtered": {
                "query": {
                    "match_all": {}
                },
                "filter": {
                    "range": {
                        "last_updated": {
                            "gte": "2013-01-01 00:00:00"
                        }
                    }
                }
            }
        }
    }
    '
    
    0 讨论(0)
提交回复
热议问题