2017-05-03 114 views
0

我想取一個文件我已經通過elasticsearch索引的以下部分不返回結果:範圍查詢在Elasticsearch

temporal: { 
begin: "2016-11-30T00:00:00", 
end: "2016-12-08T13:55:02" 
}, 

,我使用上的捲曲,因爲我目前只是測試查詢的查詢在localhost是下列之一:

curl -XGET 'localhost:9201/_search?pretty' -H 'Content-Type: application/json' -d' 
{ 
    "query": { 
     "range" : { 
      "timestamp" : { 
       "gte": "2015-01-01 00:00:00", 
       "lte": "now" 
      } 
     } 
    } 
} 
' 

映射

temporal: { 
properties: { 
begin: { 
type: "date" 
}, 
end: { 
type: "date" 
} 
} 
} 

但上述查詢不會返回任何成功的匹配,但它至少應返回上述文檔。

+0

你沒有你在上面文檔中的任何'timestamp'場。 – Val

+0

@val我試圖通過將查詢中的時間戳字段更改爲時態,但它仍然沒有生成任何結果 – Rehan

+1

您需要根據您要檢查的數據字段將其更改爲'temporal.begin'或'temporal.end' 。 – Val

回答

0

假設你想搜索你發佈的(注意我已經格式化日期時間輸入),這是時間戳 - 映射會。

{ 
    "temporal" : { 
    "mappings" : { 
     "doc" : { 
     "properties" : { 
      "temporal" : { 
      "properties" : { 
       "begin" : { 
       "type" : "date", 
       "format" : "strict_date_optional_time||epoch_millis" 
       }, 
       "end" : { 
       "type" : "date", 
       "format" : "strict_date_optional_time||epoch_millis" 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 

索引/查詢文件:

curl -XPOST localhost:9200/temporal/doc/1 -d ' 
{"temporal": { 
"begin": "2016-11-30T00:00:00", 
"end": "2016-12-08T13:55:02" 
}}'; 


curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' 
    { 
     "query": { 
      "range" : { 
       "temporal.begin" : { 
        "gte": "2015-01-01T00:00:00", 
        "lte": "now" 
       } 
      } 
     } 
    }' 
    { 
     "took" : 6, 
     "timed_out" : false, 
     "_shards" : { 
     "total" : 108, 
     "successful" : 108, 
     "failed" : 0 
     }, 
     "hits" : { 
     "total" : 1, 
     "max_score" : 1.0, 
     "hits" : [ { 
      "_index" : "temporal", 
      "_type" : "doc", 
      "_id" : "1", 
      "_score" : 1.0, 
      "_source" : { 
      "temporal" : { 
       "begin" : "2016-11-30T00:00:00", 
       "end" : "2016-12-08T13:55:02" 
      } 
      } 
     } ] 
     } 
    }