【问题标题】:elasticsearch not analyzed still tokenize string未分析的弹性搜索仍然标记字符串
【发布时间】:2014-06-06 02:39:17
【问题描述】:

我有一个包含 4 个条目的索引。

  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "da_6",
      "_type" : "tweet",
      "_id" : "1",
      "_score" : 1.0, "_source" : {
    "message" : "hello world"
}
    }, {
      "_index" : "da_6",
      "_type" : "tweet",
      "_id" : "2",
      "_score" : 1.0, "_source" : {
    "message" : "hello worldetc"
}
    }, {
      "_index" : "da_6",
      "_type" : "tweet",
      "_id" : "4",
      "_score" : 1.0, "_source" : {
    "message" : "etc hello world"
}
    }, {
      "_index" : "da_6",
      "_type" : "tweet",
      "_id" : "3",
      "_score" : 1.0, "_source" : {
    "message" : "hello etc world"
}
    } ]

我在创建索引时已将映射设置为“string”/“not_analyzed”,我确信它已被应用。

映射:

"da_6" : {
    "mappings" : {
      "tweet" : {
        "properties" : {
          "message" : {
            "type" : "string",
            "index" : "not_analyzed"
          }
        }
      }
    }
  }

当用户键入“hello w”时,我希望它首先显示第一个,然后是第二个和第三个。由于第四个不包含“hello w”作为一个完整的字符串,它不应该显示在结果中。

我试过query_string,搜索“hello w*”,但它显示了所有 4 个结果(似乎仍在标记内容。

是否有类似IndexOf (js) 的搜索方法给出的结果只包含给定的查询字符串(在这种情况下为“hello w”)?

【问题讨论】:

  • 第四个条目在哪里?
  • 我已经更新了我的问题。
  • 您的查询的问题可能是您没有提供默认字段。比使用 _all 字段。如果您提供默认字段作为消息,您将获得其他结果。不过,我还没有(还)你的问题的答案。

标签: elasticsearch


【解决方案1】:

也许您可以使用 match_phrase_prefix 查询,我可以返回您想要的三个项目。我确实使用了另一个映射。我使用标准分析器(所以没有索引:not_analyzed):

GET /da_6/_search
{
  "query": {
    "match_phrase_prefix": {
      "message": "hello w"
    }
  }
}

【讨论】:

  • Jettro,感谢您的回答。实际上,我之前使用的是“match_phrase_prefix”。但是,当涉及到更多数据时,elasticsearch 似乎会在查询达到 max_expansion 后停止查询,以便提高性能。在这种情况下,它可能会错过一些正确的结果
  • 根据您的问题,我无法理解文本的大小。
猜你喜欢
  • 1970-01-01
  • 2021-06-28
  • 2014-09-02
  • 1970-01-01
  • 2016-09-04
  • 1970-01-01
  • 1970-01-01
  • 2017-01-09
  • 1970-01-01
相关资源
最近更新 更多