使用 multimatch elasticsearch 的 bool 查询中的模糊性 [英] fuzziness in bool query with multimatch elasticsearch
问题描述
我使用的是elasticsearch 6.3.0 版.我想将模糊性与多重匹配一起使用.但没有选择.有人可以为我提供解决方案吗?提前致谢查询:
i am using elasticsearch version 6.3.0. I want to use fuzziness along with multimatch. but there is no option for that. Can anybody provide me a solution ? Thanks in advance Query :
{ "query": {
"bool": {
"must": [
{"function_score": {
"query": {
"multi_match": {
"query": "local",
"fields": [
"user.name^3",
"main_product"
],
"type": "phrase"
}
}
}}
],
"filter": {
"geo_distance": {
"distance": "1000km",
"user.geolocation": {
"lat": 25.55,
"lon": -84.44
}
}
}
}
} }
推荐答案
查看您现有的查询,您正在寻找
Looking at your existing query, you are looking for mix of
- 基于字段的提升
- 多字段匹配
- 词组匹配
- 模糊匹配
如果不是 phrase_match
,您可以根据您的要求简单地添加 "fuzziness": "AUTO"
或 "fuzziness":1 或任何数字
在你现有的查询中,你会得到你想要的.
If it isn't phrase_match
you can simply add "fuzziness": "AUTO"
or "fuzziness":1 or whatever number based on your requirement
in your existing query and you'd get what you are looking for.
POST <your_index_name>/_search
{
"query":{
"bool":{
"must":[
{
"function_score":{
"query":{
"multi_match":{
"query":"local",
"fields":[
"user.name^3",
"main_product"
],
"fuzziness":"AUTO"
}
}
}
}
],
"filter":{
"geo_distance":{
"distance":"1000km",
"user.geolocation":{
"lat":25.55,
"lon":-84.44
}
}
}
}
}
}
模糊短语:
在这种情况下,您需要使用 跨度查询
为了简单起见,我放弃了过滤部分,并提出了以下查询.假设我正在搜索名为 pearl jam
的短语.
I've discarded the filtering part just for the sake of simplicity and came up with the below query. And let's say that I am searching for phrase called pearl jam
.
POST <your_index_name>/_search
{
"query":{
"function_score":{
"query":{
"bool":{
"should":[
{
"bool":{
"boost":3,
"must":[
{
"span_near":{
"clauses":[
{
"span_multi":{
"match":{
"fuzzy":{
"user.name":"pearl"
}
}
}
},
{
"span_multi":{
"match":{
"fuzzy":{
"user.name":"jam"
}
}
}
}
],
"slop":0,
"in_order":true
}
}
]
}
},
{
"bool":{
"boost":1,
"must":[
{
"span_near":{
"clauses":[
{
"span_multi":{
"match":{
"fuzzy":{
"main_product":"pearl"
}
}
}
},
{
"span_multi":{
"match":{
"fuzzy":{
"main_product":"jam"
}
}
}
}
],
"slop":0,
"in_order":true
}
}
]
}
}
]
}
}
}
}
}
所以我正在做的是基于模糊匹配的多字段短语中的字段对称为pearl jam
的短语执行增强.
So what I am doing is performing boosting based on fields in multi-field phrase with fuzzy match for phrase called pearl jam
.
拥有 slop: 0
和 in_order:true
将使我能够对我在子句中指定的单词进行短语匹配.
Having slop: 0
and in_order:true
would enable me to do phrase match for the words I've specified in the clauses.
如果您有任何疑问,请告诉我.
Let me know if you have any queries.
这篇关于使用 multimatch elasticsearch 的 bool 查询中的模糊性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!