弹性搜索查询词返回所有数据

时间:2016-09-13 21:23:58

标签: elasticsearch

我正在尝试查询我的ES,这是我的数据, 你可以在意义上运行它,它创建索引fst并用4个项填充它。 然后你可以看到它返回错误的结果编号 我只想要一个结果,就像这样。

PUT fst/objects/ggg
{
    "frameAttributes": {
    "identities": [
     { "_id": "DSC00263",   "_score": 0.655822},
     { "_id": "DSC00262",   "_score": 0.59957 },
     { "_id": "DSC00244",   "_score": 0.220819},
     { "_id": "DSC00300",   "_score": 0.191191},
     {"_id": "DSC00276",    "_score": 0.124561}

    ]
    }
}
PUT fst/objects/ffffff
 {
   "frameAttributes": {
    "identities": [
         {"_id": "DSC00222","_score": 0.191009},
         {"_id": "DSC00261","_score": 0.146157},
         {"_id": "DSC00329","_score": 0.14518},
         {"_id": "DSC00225","_score": 0.12622},
         {"_id": "DSC00295","_score": 0.12396}
      ]
   }

}
PUT fst/objects/aaaa
 {
   "frameAttributes": {
       "identities": [
         {"_id": "DSC00229","_score": 0.223149},
         {"_id": "DSC00240","_score": 0.178388},
         {"_id": "DSC00228","_score": 0.173769},
         {"_id": "DSC00257","_score": 0.166746},
         {"_id": "DSC00226","_score": 0.153071}
      ]
   }
 }
put fst/objects/abcdef
{
   "frameAttributes": {
     "identities": [
         { "_id": "DSC00262","_score": 0.427957},
         {"_id": "DSC00263","_score": 0.408772},
         {"_id": "DSC00282","_score": 0.284546 },
         { "_id": "DSC00283","_score": 0.191374},
         {"_id": "DSC00299", "_score": 0.165478}
      ]
   }
}

我的查询应该只返回一个结果

get fst/_search
{
    "query": {
        "term": {
           "frameAttributes.identities._id": {
              "value": "DSC00229"
           }
        }
    }
}

2 个答案:

答案 0 :(得分:2)

您必须将所需字段设置为not_analyzed。在您的情况下,该字段为_id。您可以在创建索引时执行此操作。例如:

PUT /gb/_mapping/tweet
{
  "properties" : {
    "tag" : {
      "type" :    "string",
      "index":    "not_analyzed"
    }
  }
}

点击此链接以获取参考:https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html

答案 1 :(得分:0)

花了一段时间 但我学到了一些新的弹性搜索并不像你想要创建一个名为_id的字段。我将其更改为personId,现在它正常工作。

全部谢谢:)