使用ElasticSeach搜索字符串的一部分 [英] Search part of string with ElasticSeach
问题描述
在ElasticSearch中,我尝试使其搜索单词的一部分. 我的示例数据是
In ElasticSearch, I tried to makeit search for a part of a word. My example data is
{
"_id" : "1",
"name" : "Nopales",
}
{
"_id" : "2",
"name" : "ginger ale",
}
{
"_id" : "3",
"name" : "Kale",
}
{
"_id" : "4",
"name" : "Triticale Flour Whole Grain",
}
并且请求是找到与单词"ale is"匹配的单词
and the request is to find the matching words with the word "ale is"
GET /_search
{
"query": {
"query_string" : {"default_field" : "name", "query" : "*ale*"}
}
}
,它返回类似
Kale, Triticale Flour Whole Grain, ginger ale, Nopales
但最匹配的是姜汁啤酒,其中包含准确的单词,然后是羽衣甘蓝,然后是基于单词计数的胭脂红,然后是黑小麦面粉全谷物. 任何人都知道如何实现这一目标吗?
but the best match is ginger ale, which contains the exact word, then kale, then nopales based on word counts then Triticale Flour Whole Grain. Anyone have idea how to achieve this?
推荐答案
我认为您应该使用*ale
.在查询中,它在name
字段的所有值中搜索ale
.这些所有Kale, Triticale Flour Whole Grain, ginger ale, Nopales
值都包含ale
.当您使用*ale
查询时,它将搜索以ale
结尾的字符串.您也可以像这样"query" : "(*ale)OR(ale*)"
将其用于其他种类的通配符.
I think you should use *ale
. In your query it searching for ale
in all values of name
field. And these all values Kale, Triticale Flour Whole Grain, ginger ale, Nopales
contains ale
. When you will query with *ale
, It will search for string which ending with ale
. You can also use like this "query" : "(*ale)OR(ale*)"
for different kind of wildcards.
这篇关于使用ElasticSeach搜索字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!