gpt4 book ai didi

elasticsearch - Elasticsearch仅找到完美匹配

转载 作者:行者123 更新时间:2023-12-02 22:52:01 25 4
gpt4 key购买 nike

我一直在尝试这样做,阅读和搜索了很多内容,但没有找到任何明确的答案或解决方案。

假设我们添加了一些文档:

$ curl -XPUT http://localhost:9200/tm/entries/1 -d '{"item": "foo" }'
{"_index":"tm","_type":"entries","_id":"1","_version":1,"created":true}

$ curl -XPUT http://localhost:9200/tm/entries/2 -d '{"item": "foo bar" }'
{"_index":"tm","_type":"entries","_id":"2","_version":1,"created":true}

$ curl -XPUT http://localhost:9200/tm/entries/3 -d '{"item": "foo bar foo" }'
{"_index":"tm","_type":"entries","_id":"3","_version":1,"created":true}

在此之后,我只想查找与搜索查询完全匹配的文档
$ curl -XGET http://localhost:9200/_search?q=foo

结果包含所有3个文档,我只想获取仅与“foo”匹配的文档,别无其他。

也,
$ curl -XGET http://localhost:9200/_search?q=bar foo

不应该返回任何结果。
  • Elasticsearch可以这样做吗?
  • 怎么样?

  • 更新:
    现有映射:
    {
    "tm": {
    "mappings": {
    "entries": {
    "properties": {
    "item": {
    "type": "string"
    }
    }
    }
    }
    }
    }

    最佳答案

    使用以下映射。

    {
    "tm": {
    "mappings": {
    "entries": {
    "properties": {
    "item": {
    "type": "string",
    "index" : "not_analyzed"
    }
    }
    }
    }
    }
    }

    并使用术语查询来查找完全匹配。不分析术语查询。 refer
    curl -XGET "http://localhost:9200/tm/entries/_search" -d'
    {
    "query": {
    "term": {
    "item": {
    "value": "foo bar"
    }
    }
    }
    }'

    关于elasticsearch - Elasticsearch仅找到完美匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24905534/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com