如何从弹性搜索查询中获取准确的搜索结果

时间:2019-05-30 06:53:14

标签: python amazon-web-services elasticsearch

我需要弹性搜索查询的精确匹配结果

在使用以下curl命令建立索引时,我尝试将索引保持为“未分析”:

curl -X PUT es/_doc/all -H'Content-Type: application/json' -d '{
  "mappings": {
    "dynamic_templates": [
      {
        "example_string_as_object": {
          "match_mapping_type": "object",
          "match":   "x-example",
          "mapping": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    ]
  }
  }'

但是,当我尝试使用“ account-validity”进行查询时,却同时获得了“ account”和“ validity”的结果。

我需要显示仅具有“帐户有效期”的文档的结果。 我正在使用的查询:

es / _search?size = 1000&from = 0&q = account-validity&pretty = true

有人可以帮我吗

1 个答案:

答案 0 :(得分:0)

我能够通过在需要精确搜索的数据之前使用参数“ term”来解决此问题。

PFB示例,显示名称= ABC的完全匹配

networkx