2016-05-20 29 views
0

不支持話說日期格式,我不能與日期格式彈性搜索來搜索彈性檢索失敗,在指數

我創建的索引和字段映射出的日期格式,但查詢失敗。

在加載數據之前,我使用映射創建了一個索引,並將我的數據加載到彈性搜索中。

"mappings": { 
    "workers": { 
     "person.birthDate": { 
      "full_name": "person.birthDate", 
      "mapping": { 
       "birthDate": { 
       "type": "date", 
       "format": "yyyy-MM-dd||epoch_millis" 
       } 
      } 
     } 

我輸入的查詢是如下

POST _search 
{ 
    "query": { 


    "bool" : { 
    "must" : [ { 
     "match" : { 
     "person.birthDate" : { 
      "query" : "1968-06-15", 
      "type" : "date" 
     } 
     } 
    } ] 
    } 



    }, 
    "from": 0, 
    "size": 10, 
    "sort": [], 
    "aggs": {} 
} 

和輸出

{ 
    "error": { 
     "root_cause": [ 
     { 
      "type": "query_parsing_exception", 
      "reason": "[match] query does not support type date", 
      "index": "index1", 
      "line": 9, 
      "col": 33 
     } 
     ], 
     "type": "search_phase_execution_exception", 
     "reason": "all shards failed", 
     "phase": "query", 
     "grouped": true, 
     "failed_shards": [ 
     { 
      "shard": 0, 
      "index": "index1", 
      "node": "RewaFar_TsGVGz1RmgOxlA", 
      "reason": { 
       "type": "query_parsing_exception", 
       "reason": "[match] query does not support type date", 
       "index": "index1", 
       "line": 9, 
       "col": 33 
      } 
     } 
     ] 
    }, 
    "status": 400 
} 

任何幫助,在此,將不勝感激。 請注意,我對彈性搜索很陌生。

回答

1

以上不是有效的match查詢。 type:date不適用於匹配查詢。
如果要過濾日期,建議使用range query

例子:

put test 
{ 
    "mappings": { 
     "test": { 
       "properties" : { 
        "birthDate": { 
         "type": "date", 
         "format": "yyyy-MM-dd||epoch_millis" 
        } 
       } 
      } 
    } 
} 

put test/test/1 
{ 
    "birthDate" : "2016-05-20" 
} 

##timestamp for 2016-05-20 19:00:24 GMT 
put test/test/2 
{ 
    "birthDate" : 1463771107000 
} 

post test/test/_search 
{ 
    "query": { 
     "range" : { 
      "birthDate" : { 
       "gte" : "2016-05-20", 
       "lt" : "2016-05-21", 
       "format": "yyyy-MM-dd||epoch_millis" 
      } 
    } 
} 


    "hits": [ 
    { 
     "_index": "test", 
     "_type": "test", 
     "_id": "2", 
     "_score": 1, 
     "_source": { 
      "birthDate": 1463771107000 
     } 
    }, 
    { 
     "_index": "test", 
     "_type": "test", 
     "_id": "1", 
     "_score": 1, 
     "_source": { 
      "birthDate": "2016-05-20" 
     } 
    } 
    ] 
+0

這worked.thanks爲help.meant爲接受的答案後期更新而回SRY。 – Fryder