2016-04-27 97 views
1

我有一些文檔和查詢的映射再次術語確實失敗。我不明白爲什麼:elasticsearch:術語查詢失敗

"mappings":{ 
    "timeslot":{ 
      "properties":{ 
       "FOB_IN":{ 
         "type":"long" 
       }, 
       "TRIGGER_CODE":{ 
         "type":"long" 
       }, 
       "FLIGHT_PHASE":{ 
         "type":"long" 
       }, 
       "REP16_TRIG":{ 
         "type":"long" 
       }, 
       "fwot":{ 
         "type":"string" 
       }, 
       "FOB_OUT":{ 
         "type":"long" 
       }, 
       "FP":{ 
         "type":"long" 
       }, 
       "FLTNB":{ 
         "type":"string" 
       }, 
       "Date":{ 
         "format":"strict_date_optional_time||epoch_millis", 
         "type":"date" 
       } 
      } 
    } 
} 

我可以做一個長期的查詢對TRIGGER_CODE,例如,和

{ 
    "took": 1, 
    "timed_out": false, 
    "_shards": { 
     "total": 1, 
     "successful": 1, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 5, 
     "max_score": 4.4446826, 
     "hits": [ 
     { 
      "_index": "merged-2016-04", 
      "_type": "timeslot", 
      "_id": "AVRS8VnirVLwfvMnwpXb", 
      "_score": 4.4446826, 
      "_source": { 
       "Date": "2016-04-03T08:42:44+0000", 
       "FLIGHT_PHASE": 20, 
       "TRIGGER_CODE": 4000, 
       "fwot": "A6-APA" 
      } 
     } 
     ] 
    } 
} 

現在同樣對fwot不會失敗它工作正常。怎麼了?

GET merged-2016-04/_search?size=1 
{ 
    "query" : { 
     "term" : { "fwot": "A6-APA"} 
    } 
} 

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

你需要'fwot'是'「指數」:「not_analyzed」'對於工作。而且您需要重新編制數據以便上述更改生效。 –

+0

這意味着映射應該是這樣的:''fwot「:{ 」type「:」string「,」index「:」not_analyzed「 }' –

+0

query case.example:」term「:{」fwot「 : 「A6-APA」} } –

回答

2

你需要fwot是"index": "not_analyzed"該工作。而且您需要重新編制數據以便上述更改生效。

下面是映射的變化和一些測試數據的命令的完整列表:

PUT /merged-2016-04 
{ 
    "mappings": { 
    "timeslot": { 
     "properties": { 
     "FOB_IN": { 
      "type": "long" 
     }, 
     "TRIGGER_CODE": { 
      "type": "long" 
     }, 
     "FLIGHT_PHASE": { 
      "type": "long" 
     }, 
     "REP16_TRIG": { 
      "type": "long" 
     }, 
     "fwot": { 
      "type": "string", 
      "index": "not_analyzed" 
     }, 
     "FOB_OUT": { 
      "type": "long" 
     }, 
     "FP": { 
      "type": "long" 
     }, 
     "FLTNB": { 
      "type": "string" 
     }, 
     "Date": { 
      "format": "strict_date_optional_time||epoch_millis", 
      "type": "date" 
     } 
     } 
    } 
    } 
} 

POST /merged-2016-04/timeslot 
{ 
    "Date": "2016-04-03T08:42:44+0000", 
    "FLIGHT_PHASE": 20, 
    "TRIGGER_CODE": 4000, 
    "fwot": "A6-APA" 
} 

GET merged-2016-04/_search?size=1 
{ 
    "query": { 
    "term": { 
     "fwot": "A6-APA" 
    } 
    } 
} 
+0

謝謝安德烈,它工作得很好 –