Different multi match for each mapping in one query
I have 4 different mappings: A, B, C and D.
For mappings A and B the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "keyword",
"fuzziness": "AUTO",
"fields": ["name*"]
}
}
]
}
}
]
}
},
"from": 0,
"size": 20
}
For C the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": "AUTO",
"use_dis_max": false,
"fields": ["name*"]
}
}
]
}
}
]
}
}
}
And for D the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": 0,
"use_dis_max": false,
"fields": ["name*"]
}
},
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": 3,
"fields": ["name*"]
}
}
]
}
}
]
}
}
}
I can make 3 separate queries and process the results but it turns out to be messy and takes longer. Is it possible to combine these 3 queries into one and say for mapping/types A and B use the first multi match for C use the second and for D use the third.
elasticsearch elasticsearch-5 spring-data-elasticsearch
add a comment |
I have 4 different mappings: A, B, C and D.
For mappings A and B the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "keyword",
"fuzziness": "AUTO",
"fields": ["name*"]
}
}
]
}
}
]
}
},
"from": 0,
"size": 20
}
For C the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": "AUTO",
"use_dis_max": false,
"fields": ["name*"]
}
}
]
}
}
]
}
}
}
And for D the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": 0,
"use_dis_max": false,
"fields": ["name*"]
}
},
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": 3,
"fields": ["name*"]
}
}
]
}
}
]
}
}
}
I can make 3 separate queries and process the results but it turns out to be messy and takes longer. Is it possible to combine these 3 queries into one and say for mapping/types A and B use the first multi match for C use the second and for D use the third.
elasticsearch elasticsearch-5 spring-data-elasticsearch
add a comment |
I have 4 different mappings: A, B, C and D.
For mappings A and B the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "keyword",
"fuzziness": "AUTO",
"fields": ["name*"]
}
}
]
}
}
]
}
},
"from": 0,
"size": 20
}
For C the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": "AUTO",
"use_dis_max": false,
"fields": ["name*"]
}
}
]
}
}
]
}
}
}
And for D the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": 0,
"use_dis_max": false,
"fields": ["name*"]
}
},
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": 3,
"fields": ["name*"]
}
}
]
}
}
]
}
}
}
I can make 3 separate queries and process the results but it turns out to be messy and takes longer. Is it possible to combine these 3 queries into one and say for mapping/types A and B use the first multi match for C use the second and for D use the third.
elasticsearch elasticsearch-5 spring-data-elasticsearch
I have 4 different mappings: A, B, C and D.
For mappings A and B the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "keyword",
"fuzziness": "AUTO",
"fields": ["name*"]
}
}
]
}
}
]
}
},
"from": 0,
"size": 20
}
For C the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": "AUTO",
"use_dis_max": false,
"fields": ["name*"]
}
}
]
}
}
]
}
}
}
And for D the following query gives best results:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": 0,
"use_dis_max": false,
"fields": ["name*"]
}
},
{
"multi_match": {
"query": "....",
"analyzer": "simple",
"fuzziness": 3,
"fields": ["name*"]
}
}
]
}
}
]
}
}
}
I can make 3 separate queries and process the results but it turns out to be messy and takes longer. Is it possible to combine these 3 queries into one and say for mapping/types A and B use the first multi match for C use the second and for D use the third.
elasticsearch elasticsearch-5 spring-data-elasticsearch
elasticsearch elasticsearch-5 spring-data-elasticsearch
asked Nov 21 '18 at 10:50
Sterling DuchessSterling Duchess
812123878
812123878
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I came up with below using Type Query.
For sake of simplicity I've only considered queries for type C and D as mentioned in the question.
Note that I've also included boost parameter and I've mentioned it in such a way that documents of type C would always appear higher in results as compared to documents of type D.
You can go ahead and make changes according to your requirements.
Query
POST <your_index_name>/_search
{
"query":{
"bool":{
"should":[
{
"bool":{
"boost":100,
"must":[
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":"AUTO",
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"type":{
"value":"C"
}
}
]
}
},
{
"bool":{
"boost":5,
"must":[
{
"type":{
"value":"D"
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":0,
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":3,
"fields":[
"name*"
]
}
}
]
}
}
]
}
}
}
Let me know if this helps!
hello, did the above solution help? Are you looking for something else?
– Kamal
Nov 23 '18 at 8:37
1
Hi yes it did help thank you very much I just forgot to upvote/accept it.
– Sterling Duchess
Nov 27 '18 at 12:04
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%2f53410488%2fdifferent-multi-match-for-each-mapping-in-one-query%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I came up with below using Type Query.
For sake of simplicity I've only considered queries for type C and D as mentioned in the question.
Note that I've also included boost parameter and I've mentioned it in such a way that documents of type C would always appear higher in results as compared to documents of type D.
You can go ahead and make changes according to your requirements.
Query
POST <your_index_name>/_search
{
"query":{
"bool":{
"should":[
{
"bool":{
"boost":100,
"must":[
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":"AUTO",
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"type":{
"value":"C"
}
}
]
}
},
{
"bool":{
"boost":5,
"must":[
{
"type":{
"value":"D"
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":0,
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":3,
"fields":[
"name*"
]
}
}
]
}
}
]
}
}
}
Let me know if this helps!
hello, did the above solution help? Are you looking for something else?
– Kamal
Nov 23 '18 at 8:37
1
Hi yes it did help thank you very much I just forgot to upvote/accept it.
– Sterling Duchess
Nov 27 '18 at 12:04
add a comment |
I came up with below using Type Query.
For sake of simplicity I've only considered queries for type C and D as mentioned in the question.
Note that I've also included boost parameter and I've mentioned it in such a way that documents of type C would always appear higher in results as compared to documents of type D.
You can go ahead and make changes according to your requirements.
Query
POST <your_index_name>/_search
{
"query":{
"bool":{
"should":[
{
"bool":{
"boost":100,
"must":[
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":"AUTO",
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"type":{
"value":"C"
}
}
]
}
},
{
"bool":{
"boost":5,
"must":[
{
"type":{
"value":"D"
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":0,
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":3,
"fields":[
"name*"
]
}
}
]
}
}
]
}
}
}
Let me know if this helps!
hello, did the above solution help? Are you looking for something else?
– Kamal
Nov 23 '18 at 8:37
1
Hi yes it did help thank you very much I just forgot to upvote/accept it.
– Sterling Duchess
Nov 27 '18 at 12:04
add a comment |
I came up with below using Type Query.
For sake of simplicity I've only considered queries for type C and D as mentioned in the question.
Note that I've also included boost parameter and I've mentioned it in such a way that documents of type C would always appear higher in results as compared to documents of type D.
You can go ahead and make changes according to your requirements.
Query
POST <your_index_name>/_search
{
"query":{
"bool":{
"should":[
{
"bool":{
"boost":100,
"must":[
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":"AUTO",
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"type":{
"value":"C"
}
}
]
}
},
{
"bool":{
"boost":5,
"must":[
{
"type":{
"value":"D"
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":0,
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":3,
"fields":[
"name*"
]
}
}
]
}
}
]
}
}
}
Let me know if this helps!
I came up with below using Type Query.
For sake of simplicity I've only considered queries for type C and D as mentioned in the question.
Note that I've also included boost parameter and I've mentioned it in such a way that documents of type C would always appear higher in results as compared to documents of type D.
You can go ahead and make changes according to your requirements.
Query
POST <your_index_name>/_search
{
"query":{
"bool":{
"should":[
{
"bool":{
"boost":100,
"must":[
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":"AUTO",
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"type":{
"value":"C"
}
}
]
}
},
{
"bool":{
"boost":5,
"must":[
{
"type":{
"value":"D"
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":0,
"use_dis_max":false,
"fields":[
"name*"
]
}
},
{
"multi_match":{
"query":"....",
"analyzer":"simple",
"fuzziness":3,
"fields":[
"name*"
]
}
}
]
}
}
]
}
}
}
Let me know if this helps!
answered Nov 21 '18 at 12:28
KamalKamal
2,31711022
2,31711022
hello, did the above solution help? Are you looking for something else?
– Kamal
Nov 23 '18 at 8:37
1
Hi yes it did help thank you very much I just forgot to upvote/accept it.
– Sterling Duchess
Nov 27 '18 at 12:04
add a comment |
hello, did the above solution help? Are you looking for something else?
– Kamal
Nov 23 '18 at 8:37
1
Hi yes it did help thank you very much I just forgot to upvote/accept it.
– Sterling Duchess
Nov 27 '18 at 12:04
hello, did the above solution help? Are you looking for something else?
– Kamal
Nov 23 '18 at 8:37
hello, did the above solution help? Are you looking for something else?
– Kamal
Nov 23 '18 at 8:37
1
1
Hi yes it did help thank you very much I just forgot to upvote/accept it.
– Sterling Duchess
Nov 27 '18 at 12:04
Hi yes it did help thank you very much I just forgot to upvote/accept it.
– Sterling Duchess
Nov 27 '18 at 12:04
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%2f53410488%2fdifferent-multi-match-for-each-mapping-in-one-query%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