一尘不染

elasticsearch:词条查询失败

elasticsearch

我有一些文档的映射,并且查询agains条件确实失败。我不明白为什么:

"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": []
   }
}

阅读 300

收藏
2020-06-22

共1个答案

一尘不染

您需要为此"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"
    }
  }
}
2020-06-22