我有一个包含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”)?

最佳答案

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

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

关于elasticsearch - 没有分析elasticsearch仍然标记化字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23207441/

10-09 07:22
查看更多