我正在 Elasticsearch 中寻找一种搜索类型,它返回包含关键字的所有字符串。以下查询仅在整个文本为“google”时匹配(不区分大小写,因此它也匹配 Google 或 GooGlE 等)。如何匹配另一个字符串中的“google”,或者即使我写了“goog”?
query: {
bool : {
must: {
match: { text: 'google'}
}
}
}
最佳答案
How do I match for the 'google' inside of another string or even if I write 'goog'?
Wildcard query可以帮助您在字段中找到您要查找的子文本。
在您的情况下,它将如下所示。 (无论前后文本是什么,它都会返回存在文本 goog
的任何文档,例如:this is google
OR he is google the answer
)
GET /_search
{
"query": {
"wildcard": {
"field_name": {
"value": "*goog*",
}
}
}
}
关于java - 返回包含用户在 Elasticsearch 中输入的关键字的字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59363490/