【问题标题】:elastic search query term returns all the data弹性搜索查询词返回所有数据
【发布时间】:2017-01-21 14:19:29
【问题描述】:

我正在尝试查询我的 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"
           }
        }
    }
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您必须将必填字段设置为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

    【讨论】:

      【解决方案2】:

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

      谢谢大家:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-01
        • 2019-07-20
        • 1970-01-01
        相关资源
        最近更新 更多