2015-07-03 95 views
1

我試圖在elasticsearch中建立一個索引,然後搜索數字字段。結果集是空的,即使你的邏輯結果是有一個記錄結果集。Elasticsearch中的數字範圍/過濾器

下面的操作來再現(使用感)

創建索引

PUT playground 

創建

POST playground/doc 
{ 
    "value": { 
     "textlabel": "Lorem Ipsum", 
     "numerlabel": 37.0, 
     "datelabel":"1978-10-26T00:00:00+02:00" 
    } 
} 

自動生成的映射文件似乎提供了一個文件正確的數據類型

{ 
    "playground": { 
     "mappings": { 
     "doc": { 
      "properties": { 
       "value": { 
        "properties": { 
        "datelabel": { 
         "type": "date", 
         "format": "dateOptionalTime" 
        }, 
        "numerlabel": { 
         "type": "double" 
        }, 
        "textlabel": { 
         "type": "string" 
        } 
        } 
       } 
      } 
     } 
     } 
    } 
} 

上的日期範圍搜索工作正常,返回預期數據

POST playground/doc/_search 
{ 
    "query": {   
     "filtered": {   
      "filter": { 
       "range" : { 
        "value.datelabel" : {       
         "lte": "now-28y" 
        } 
       } 
      } 
     } 
    } 
} 

但數值範圍不

返回任何結果

POST playground/doc/_search 
{ 
    "query": { 
     "filtered": {   
      "filter": { 
       "range": { 
        "value.numberlabel" : {    
         "lte": 100 
        } 
       } 
      } 
     } 
    } 
} 

結果

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

任何建議爲什麼?

回答

1

你有一個錯字:numerlabel - numberlabel。正確的查詢,給定映射是:

{ 
    "query": { 
    "filtered": { 
     "filter": { 
     "range": { 
      "value.numerlabel": { 
      "lte": 100 
      } 
     } 
     } 
    } 
    } 
} 
+0

謝謝安德烈 - 我檢查了100次查詢的拼寫......但沒有看文檔的創建。非常感謝! –

1

您剛剛拼錯了拼寫。 "numerlabel"在您的文檔中,但"value.numberlabel"在您的查詢中。

後,我跑了你的設置代碼,這個工程:

POST playground/doc/_search 
{ 
    "query": { 
     "filtered": {   
      "filter": { 
       "range": { 
        "value.numerlabel" : {    
         "lte": 100 
        } 
       } 
      } 
     } 
    } 
} 
... 
{ 
    "took": 3, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 1, 
     "max_score": 1, 
     "hits": [ 
     { 
      "_index": "playground", 
      "_type": "doc", 
      "_id": "AU5UiwngQAg_uFp56nys", 
      "_score": 1, 
      "_source": { 
       "value": { 
        "textlabel": "Lorem Ipsum", 
        "numerlabel": 37, 
        "datelabel": "1978-10-26T00:00:00+02:00" 
       } 
      } 
     } 
     ] 
    } 
} 
+0

謝謝斯隆,我檢查了查詢的拼寫100次......但沒有看文檔的創建。非常感謝!由於安德烈只是早一點,我會接受他的答案 - 你的答案同樣正確:) –