【问题标题】:Elasticsearch exact matches when query text is a substring当查询文本是子字符串时,Elasticsearch 完全匹配
【发布时间】:2014-08-27 17:34:05
【问题描述】:

我的 Elasticsearch 中有一个字段的数据

PUT /logs/visited_domains/1
{
"visited_domain":"microsoft.com"
}
PUT /logs/visited_domains/2
{
"visited_domain":"not-microsoft.com"
}

映射为:

{
  "properties": {
    "visited_domain": {
      "type": "string",
      "index": "not_analyzed"
    }
  }
}

当我进行 ElasticSearch 时

{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "visited_domain": "microsoft.com"
        }
      }
    }
  }
}

我会得到这两个结果。但我只想要完全匹配。关于如何更改查询或改进映射的任何想法?

编辑:我将我的一个示例从notmicrosoft.com 更改为not-microsoft.com,因为这个破折号造成了很多麻烦。 notmicrosoft.com 不会返回,但 not-microsoft.com 在搜索 microsoft.com 时会返回。

【问题讨论】:

    标签: elasticsearch exact-match


    【解决方案1】:

    使用 query_string 与引号一起使用时给出完全匹配

     "query": {
         "query_string": {
              "default_field": "visited_domain",
                    "query": "\"microsoft.com\""
                    }
      }
    

    【讨论】:

    • 我设法使用这种方法解决了我的确切问题。如果我的查询是一个变量,我不确定如何包含引号。
    猜你喜欢
    • 2015-09-02
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多