fuzziness in bool query with multimatch elasticsearch
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
}
}
}
}
} }
elasticsearch elasticsearch-6
add a comment |
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
}
}
}
}
} }
elasticsearch elasticsearch-6
add a comment |
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
}
}
}
}
} }
elasticsearch elasticsearch-6
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
}
}
}
}
} }
elasticsearch elasticsearch-6
elasticsearch elasticsearch-6
asked Nov 21 '18 at 7:29


KHUSHAL SINGHKHUSHAL SINGH
92
92
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Looking at your existing query, you are looking for mix of
- Boosting based on field
- Multifield match
- Phrase Matching
- Fuzzy Matching
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.
Fuzzy without Phrase
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
}
}
}
}
}
}
Fuzzy with Phrase:
In this case, you need to make use of Span Queries
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
}
}
]
}
}
]
}
}
}
}
}
So what I am doing is performing boosting based on fields in multi-field phrase with fuzzy match for phrase called pearl jam
.
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.
Hi Kamal, You are mentioning two different fields explicitly in two different must queries. I have to perform the same query over 100 fields. How do I perform this kind of search?
– M Nikesh
Dec 21 '18 at 10:21
I'm afraid that is not possible with Span Queries. You would need to rewrite the query for the fields. If you are creating the query on your service layer, you can come up with a loop that would run through all the fields and thereby construct the query for each and every field you are looking for.
– Kamal
Dec 22 '18 at 6:33
Thanks for your response Kamal, Unfortunately that is not a case in my Service layer since i don't have the information of the fields at the service layer.
– M Nikesh
Dec 24 '18 at 12:00
add a comment |
What makes you think there is no option for fuzziness on a multi-match query?
For example, with the data below:
http://localhost:9200/question_1/doc/_bulk
{"index":{}}
{"name" : "John Lazy", "text": "lazzi"}
{"index":{}}
{"name" : "John Lassi", "text": "lasso"}
{"index":{}}
{"name" : "Joan Labbe", "text": "lazzy"}
And this query:
http://localhost:9200/question_1/_search
{
"query": {
"multi_match" : {
"query" : "lazi",
"fields" : [ "name", "text" ],
"fuzziness": 1
}
}
}
Then I get one result, but if I change the fuzziness
parameter to 2
I'll get three results.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407151%2ffuzziness-in-bool-query-with-multimatch-elasticsearch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Looking at your existing query, you are looking for mix of
- Boosting based on field
- Multifield match
- Phrase Matching
- Fuzzy Matching
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.
Fuzzy without Phrase
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
}
}
}
}
}
}
Fuzzy with Phrase:
In this case, you need to make use of Span Queries
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
}
}
]
}
}
]
}
}
}
}
}
So what I am doing is performing boosting based on fields in multi-field phrase with fuzzy match for phrase called pearl jam
.
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.
Hi Kamal, You are mentioning two different fields explicitly in two different must queries. I have to perform the same query over 100 fields. How do I perform this kind of search?
– M Nikesh
Dec 21 '18 at 10:21
I'm afraid that is not possible with Span Queries. You would need to rewrite the query for the fields. If you are creating the query on your service layer, you can come up with a loop that would run through all the fields and thereby construct the query for each and every field you are looking for.
– Kamal
Dec 22 '18 at 6:33
Thanks for your response Kamal, Unfortunately that is not a case in my Service layer since i don't have the information of the fields at the service layer.
– M Nikesh
Dec 24 '18 at 12:00
add a comment |
Looking at your existing query, you are looking for mix of
- Boosting based on field
- Multifield match
- Phrase Matching
- Fuzzy Matching
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.
Fuzzy without Phrase
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
}
}
}
}
}
}
Fuzzy with Phrase:
In this case, you need to make use of Span Queries
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
}
}
]
}
}
]
}
}
}
}
}
So what I am doing is performing boosting based on fields in multi-field phrase with fuzzy match for phrase called pearl jam
.
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.
Hi Kamal, You are mentioning two different fields explicitly in two different must queries. I have to perform the same query over 100 fields. How do I perform this kind of search?
– M Nikesh
Dec 21 '18 at 10:21
I'm afraid that is not possible with Span Queries. You would need to rewrite the query for the fields. If you are creating the query on your service layer, you can come up with a loop that would run through all the fields and thereby construct the query for each and every field you are looking for.
– Kamal
Dec 22 '18 at 6:33
Thanks for your response Kamal, Unfortunately that is not a case in my Service layer since i don't have the information of the fields at the service layer.
– M Nikesh
Dec 24 '18 at 12:00
add a comment |
Looking at your existing query, you are looking for mix of
- Boosting based on field
- Multifield match
- Phrase Matching
- Fuzzy Matching
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.
Fuzzy without Phrase
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
}
}
}
}
}
}
Fuzzy with Phrase:
In this case, you need to make use of Span Queries
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
}
}
]
}
}
]
}
}
}
}
}
So what I am doing is performing boosting based on fields in multi-field phrase with fuzzy match for phrase called pearl jam
.
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.
Looking at your existing query, you are looking for mix of
- Boosting based on field
- Multifield match
- Phrase Matching
- Fuzzy Matching
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.
Fuzzy without Phrase
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
}
}
}
}
}
}
Fuzzy with Phrase:
In this case, you need to make use of Span Queries
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
}
}
]
}
}
]
}
}
}
}
}
So what I am doing is performing boosting based on fields in multi-field phrase with fuzzy match for phrase called pearl jam
.
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.
edited Nov 21 '18 at 10:26
answered Nov 21 '18 at 10:09


KamalKamal
1,6831920
1,6831920
Hi Kamal, You are mentioning two different fields explicitly in two different must queries. I have to perform the same query over 100 fields. How do I perform this kind of search?
– M Nikesh
Dec 21 '18 at 10:21
I'm afraid that is not possible with Span Queries. You would need to rewrite the query for the fields. If you are creating the query on your service layer, you can come up with a loop that would run through all the fields and thereby construct the query for each and every field you are looking for.
– Kamal
Dec 22 '18 at 6:33
Thanks for your response Kamal, Unfortunately that is not a case in my Service layer since i don't have the information of the fields at the service layer.
– M Nikesh
Dec 24 '18 at 12:00
add a comment |
Hi Kamal, You are mentioning two different fields explicitly in two different must queries. I have to perform the same query over 100 fields. How do I perform this kind of search?
– M Nikesh
Dec 21 '18 at 10:21
I'm afraid that is not possible with Span Queries. You would need to rewrite the query for the fields. If you are creating the query on your service layer, you can come up with a loop that would run through all the fields and thereby construct the query for each and every field you are looking for.
– Kamal
Dec 22 '18 at 6:33
Thanks for your response Kamal, Unfortunately that is not a case in my Service layer since i don't have the information of the fields at the service layer.
– M Nikesh
Dec 24 '18 at 12:00
Hi Kamal, You are mentioning two different fields explicitly in two different must queries. I have to perform the same query over 100 fields. How do I perform this kind of search?
– M Nikesh
Dec 21 '18 at 10:21
Hi Kamal, You are mentioning two different fields explicitly in two different must queries. I have to perform the same query over 100 fields. How do I perform this kind of search?
– M Nikesh
Dec 21 '18 at 10:21
I'm afraid that is not possible with Span Queries. You would need to rewrite the query for the fields. If you are creating the query on your service layer, you can come up with a loop that would run through all the fields and thereby construct the query for each and every field you are looking for.
– Kamal
Dec 22 '18 at 6:33
I'm afraid that is not possible with Span Queries. You would need to rewrite the query for the fields. If you are creating the query on your service layer, you can come up with a loop that would run through all the fields and thereby construct the query for each and every field you are looking for.
– Kamal
Dec 22 '18 at 6:33
Thanks for your response Kamal, Unfortunately that is not a case in my Service layer since i don't have the information of the fields at the service layer.
– M Nikesh
Dec 24 '18 at 12:00
Thanks for your response Kamal, Unfortunately that is not a case in my Service layer since i don't have the information of the fields at the service layer.
– M Nikesh
Dec 24 '18 at 12:00
add a comment |
What makes you think there is no option for fuzziness on a multi-match query?
For example, with the data below:
http://localhost:9200/question_1/doc/_bulk
{"index":{}}
{"name" : "John Lazy", "text": "lazzi"}
{"index":{}}
{"name" : "John Lassi", "text": "lasso"}
{"index":{}}
{"name" : "Joan Labbe", "text": "lazzy"}
And this query:
http://localhost:9200/question_1/_search
{
"query": {
"multi_match" : {
"query" : "lazi",
"fields" : [ "name", "text" ],
"fuzziness": 1
}
}
}
Then I get one result, but if I change the fuzziness
parameter to 2
I'll get three results.
add a comment |
What makes you think there is no option for fuzziness on a multi-match query?
For example, with the data below:
http://localhost:9200/question_1/doc/_bulk
{"index":{}}
{"name" : "John Lazy", "text": "lazzi"}
{"index":{}}
{"name" : "John Lassi", "text": "lasso"}
{"index":{}}
{"name" : "Joan Labbe", "text": "lazzy"}
And this query:
http://localhost:9200/question_1/_search
{
"query": {
"multi_match" : {
"query" : "lazi",
"fields" : [ "name", "text" ],
"fuzziness": 1
}
}
}
Then I get one result, but if I change the fuzziness
parameter to 2
I'll get three results.
add a comment |
What makes you think there is no option for fuzziness on a multi-match query?
For example, with the data below:
http://localhost:9200/question_1/doc/_bulk
{"index":{}}
{"name" : "John Lazy", "text": "lazzi"}
{"index":{}}
{"name" : "John Lassi", "text": "lasso"}
{"index":{}}
{"name" : "Joan Labbe", "text": "lazzy"}
And this query:
http://localhost:9200/question_1/_search
{
"query": {
"multi_match" : {
"query" : "lazi",
"fields" : [ "name", "text" ],
"fuzziness": 1
}
}
}
Then I get one result, but if I change the fuzziness
parameter to 2
I'll get three results.
What makes you think there is no option for fuzziness on a multi-match query?
For example, with the data below:
http://localhost:9200/question_1/doc/_bulk
{"index":{}}
{"name" : "John Lazy", "text": "lazzi"}
{"index":{}}
{"name" : "John Lassi", "text": "lasso"}
{"index":{}}
{"name" : "Joan Labbe", "text": "lazzy"}
And this query:
http://localhost:9200/question_1/_search
{
"query": {
"multi_match" : {
"query" : "lazi",
"fields" : [ "name", "text" ],
"fuzziness": 1
}
}
}
Then I get one result, but if I change the fuzziness
parameter to 2
I'll get three results.
answered Nov 21 '18 at 9:53


AdrienFAdrienF
437214
437214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407151%2ffuzziness-in-bool-query-with-multimatch-elasticsearch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown