elasticsearch - Elasticsearch - 在 query_string 中传递模糊参数
问题描述
我有一个自定义AUTO:10,20
模糊值的模糊查询。
{
"query": {
"match": {
"name": {
"query": "nike",
"fuzziness": "AUTO:10,20"
}
}
}
}
如何将其转换为query_string查询?我试过nike~AUTO:10,20
了,但它不工作。
解决方案
也有可能query_strng
,让我使用与 OP 提供的相同示例来展示,两者match_query
都由 OP 匹配提供,并query_string
使用相同的score
.
根据这个和这个ES 文档,Elasticsearch 支持AUTO:10,20
格式,这也在我的示例中显示。
还
索引映射
{
"mappings": {
"properties": {
"name": {
"type": "text"
}
}
}
}
索引一些文档
{
"name" : "nike"
}
使用模糊匹配搜索查询
{
"query": {
"match": {
"name": {
"query": "nike",
"fuzziness": "AUTO:10,20"
}
}
}
}
结果
"hits": [
{
"_index": "so-query",
"_type": "_doc",
"_id": "1",
"_score": 0.9808292,
"_source": {
"name": "nike"
}
}
]
具有模糊性的查询字符串
{
"query": {
"query_string": {
"fields": ["name"],
"query": "nike",
"fuzziness": "AUTO:10,20"
}
}
}
结果
"hits": [
{
"_index": "so-query",
"_type": "_doc",
"_id": "1",
"_score": 0.9808292,
"_source": {
"name": "nike"
}
}
]
推荐阅读
- node.js - 使用 nodejs 流式传输视频文件链
- c# - 在运行时加载证书时,如何确定私钥的 CSP/KSP 和密钥容器?
- gsm - FCCH - GSM 中的频率校正
- reactjs - useAuthState() 是否每次都使用 cookie 或请求?它在内部如何运作?
- python - 获取上次下载文件的下载链接 - Selenium
- java - 错误:ResultSet 没有正确定位,也许你需要调用 next
- reactjs - 显示所选图像的图像详细信息
- r - 无法在 R 闪亮中显示表格
- docker - 从 docker 容器内部访问 WAN 上的外部 IP,从 docker compose 移动到 kubernetes
- algorithm - 如何在函数中选择算法