2013-03-26 1 views
15

sto cercando per la ricerca di tutti gli elementi che hanno un campo di data all'interno di un intervallo, e viene a mancare (ha prodotto alcun risultato)filtraggio in base alla data in elasticsearch

La query:

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "match_all": {} 
     }, 
     "filter": { 
     "range": { 
      "last_updated": { 
      "from": "2013-01-01 00:00:00" 
      } 
     } 
     } 
    } 
    } 
} 

la mappatura:

{ 
    "my_doctype": { 
     "_timestamp": { 
      "enabled": "true" 
     }, 
     "properties": { 
      "cards": { 
       "type": "integer" 
      }, 
      "last_updated": { 
       "type": "date", 
       "format": "yyyy-MM-dd HH:mm:ss" 
      } 
     } 
    } 
} 

risultati in:

{ 
     took: 1 
     timed_out: false 
     _shards: { 
      total: 1 
      successful: 1 
      failed: 0 
     } 
     hits: { 
      total: 0 
      max_score: null 
      hits: [ ] 
     } 
    } 

La stessa query filtrata da un intervallo per un campo intero ("schede") con un valore numerico funziona correttamente. Anche la modifica della data anticipata (1900-01-01 00:00:00) non mostra risultati.

Cosa sto sbagliando?

BTW, so che ho il _timestamp abilitato nella mappatura, ma non è il campo da cui sto filtrando.

risposta

26

sembra funzionare bene per 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" 
        } 
       } 
      } 
     } 
    } 
} 
' 
+1

Grazie. È stato un errore di battitura da parte mia - quanto imbarazzante. Lascerò la domanda qui e segnerò come accettata, per riferimento se qualcuno ha bisogno di vedere il banco di prova. O ha più senso cancellarlo? – eran

+14

@eran Quarta corrispondenza in google per "ricerca data elasticsearch (almeno per me) .Mantieni utile, per me =) – markdsievers

+0

@Gil potresti essere più specifico? Di quale parte della query stavi parlando? – imotov