elasticsearch:术语查询失败

时间:2016-04-27 11:55:11

标签: elasticsearch

我有一些文档和查询的映射,但术语失败了。我不明白为什么:

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" } } ] } } 进行术语查询,并且工作正常

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

现在对抗fwot的确实失败了。怎么了?

didFinishLaunchingWithOptions

3 个答案:

答案 0 :(得分:4)

你需要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"
    }
  }
}

答案 1 :(得分:0)

请参阅文档页面Query DLS term query,注意“ 为什么window.moment = Moment MomentTimeZone(); 查询不匹配我的文档”以获取详细说明。

答案 2 :(得分:0)

我们可以使用关键字

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