弹性搜索中的子字符串搜索
本文关键字:搜索 字符串 | 更新日期: 2023-09-27 18:27:39
我有一个存储在弹性搜索中的文档(搜索URI为:http://localhost:9200/infypos/product/11111)数据为
{
"id": "11111",
"name": "PROMO GORE-TEX GLOVE",
"parent": "ST26923",
"price": "20"
}
现在,如果我将搜索字符串提供为"PROMO"或"GORE-TEX"或"GLOVE",我需要从文档中获取数据,就像子字符串搜索一样。我在谷歌上搜索过,但没有得到明确的答案。我应该怎么做才能进行子字符串搜索
要搜索子字符串,最好将此字段定义为未分析字段,然后使用通配符。
"query": {
"wildcard": {
"name": {
"value": "PROMO GORE*"
}
}
}
若要指定未分析的字符串,必须在将数据放入弹性搜索之前指定映射。
{
"infypos": {
"mappings": {
"product": {
"properties": {
"name": {
"type": "string",
"index": "not_analyzed"
},
"parent": {
"type": "string"
},
"price": {
"type": "long"
}
}
}
}
}
}