Unable to get similar results with a filter applied specific field











up vote
1
down vote

favorite












I am working on Elastic Search 6.4.2. I am uploading my index and mapping and my searchable fields are title,content and I want to filter the results by "test" field. The values in the test fields are abce, ghij, klmn. I want to filter the results with field "test" and value "ghij".



PUT /test_index
{
"settings": {
"index": {
"number_of_shards": 4,
"number_of_replicas": 1,
"refresh_interval": "60s",
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "my_snow"]
},
"blogs_analyzer": {
"type": "stop",
"stopwords": "_english_"
}
} ,


"filter" : {
"my_snow" : {
"type" : "snowball",
"language" : "Lovins"
}
}
}
}
},
"mappings": {
"doc": {
"_source": {
"enabled": true
},
"properties": {
"content": {
"type": "text",
"index": "true",
"store": true,
"analyzer":"my_analyzer",
"search_analyzer": "my_analyzer"
},
"host": {
"type": "keyword",
"index": "true",
"store": true

},
"title": {
"type": "text",
"index": "true",
"store": true,
"analyzer":"my_analyzer",
"search_analyzer": "my_analyzer"

},
"url": {
"type": "text",
"index": "true",
"store": true

},
"test": {
"type": "keyword",
"index": "true",
"store": true
}

}
}
}
}


I tried with the below body in order to get the results.



POST test_index/_search
{
"query": {
"bool": {
"should": [{
"match": {
"content": {
"query": "sports"

}
}
},
{
"match": {
"title": {
"query": "sports"

}
}
}
],
"filter": {
"bool": {
"must": [{
"term": {
"test": "ghij"
}
}]
}
}
}
}
}


If I send the above request I am getting lesser records and I use send direct request GET /test_index/_search?q=sports I am getting more number of results










share|improve this question






















  • The direct request queries every field in your documents while the book query restricts to just two so this is as expected if the term sports will exist in all the fields
    – ookboy24
    Nov 9 at 16:29










  • Hey @an__snatcher , the query you've posted works as expected. May I know what is it you are looking for and what is it that you are not observing? If you can update some sample documents in the question that would help us to help you. :)
    – Kamal
    Nov 9 at 18:07















up vote
1
down vote

favorite












I am working on Elastic Search 6.4.2. I am uploading my index and mapping and my searchable fields are title,content and I want to filter the results by "test" field. The values in the test fields are abce, ghij, klmn. I want to filter the results with field "test" and value "ghij".



PUT /test_index
{
"settings": {
"index": {
"number_of_shards": 4,
"number_of_replicas": 1,
"refresh_interval": "60s",
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "my_snow"]
},
"blogs_analyzer": {
"type": "stop",
"stopwords": "_english_"
}
} ,


"filter" : {
"my_snow" : {
"type" : "snowball",
"language" : "Lovins"
}
}
}
}
},
"mappings": {
"doc": {
"_source": {
"enabled": true
},
"properties": {
"content": {
"type": "text",
"index": "true",
"store": true,
"analyzer":"my_analyzer",
"search_analyzer": "my_analyzer"
},
"host": {
"type": "keyword",
"index": "true",
"store": true

},
"title": {
"type": "text",
"index": "true",
"store": true,
"analyzer":"my_analyzer",
"search_analyzer": "my_analyzer"

},
"url": {
"type": "text",
"index": "true",
"store": true

},
"test": {
"type": "keyword",
"index": "true",
"store": true
}

}
}
}
}


I tried with the below body in order to get the results.



POST test_index/_search
{
"query": {
"bool": {
"should": [{
"match": {
"content": {
"query": "sports"

}
}
},
{
"match": {
"title": {
"query": "sports"

}
}
}
],
"filter": {
"bool": {
"must": [{
"term": {
"test": "ghij"
}
}]
}
}
}
}
}


If I send the above request I am getting lesser records and I use send direct request GET /test_index/_search?q=sports I am getting more number of results










share|improve this question






















  • The direct request queries every field in your documents while the book query restricts to just two so this is as expected if the term sports will exist in all the fields
    – ookboy24
    Nov 9 at 16:29










  • Hey @an__snatcher , the query you've posted works as expected. May I know what is it you are looking for and what is it that you are not observing? If you can update some sample documents in the question that would help us to help you. :)
    – Kamal
    Nov 9 at 18:07













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am working on Elastic Search 6.4.2. I am uploading my index and mapping and my searchable fields are title,content and I want to filter the results by "test" field. The values in the test fields are abce, ghij, klmn. I want to filter the results with field "test" and value "ghij".



PUT /test_index
{
"settings": {
"index": {
"number_of_shards": 4,
"number_of_replicas": 1,
"refresh_interval": "60s",
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "my_snow"]
},
"blogs_analyzer": {
"type": "stop",
"stopwords": "_english_"
}
} ,


"filter" : {
"my_snow" : {
"type" : "snowball",
"language" : "Lovins"
}
}
}
}
},
"mappings": {
"doc": {
"_source": {
"enabled": true
},
"properties": {
"content": {
"type": "text",
"index": "true",
"store": true,
"analyzer":"my_analyzer",
"search_analyzer": "my_analyzer"
},
"host": {
"type": "keyword",
"index": "true",
"store": true

},
"title": {
"type": "text",
"index": "true",
"store": true,
"analyzer":"my_analyzer",
"search_analyzer": "my_analyzer"

},
"url": {
"type": "text",
"index": "true",
"store": true

},
"test": {
"type": "keyword",
"index": "true",
"store": true
}

}
}
}
}


I tried with the below body in order to get the results.



POST test_index/_search
{
"query": {
"bool": {
"should": [{
"match": {
"content": {
"query": "sports"

}
}
},
{
"match": {
"title": {
"query": "sports"

}
}
}
],
"filter": {
"bool": {
"must": [{
"term": {
"test": "ghij"
}
}]
}
}
}
}
}


If I send the above request I am getting lesser records and I use send direct request GET /test_index/_search?q=sports I am getting more number of results










share|improve this question













I am working on Elastic Search 6.4.2. I am uploading my index and mapping and my searchable fields are title,content and I want to filter the results by "test" field. The values in the test fields are abce, ghij, klmn. I want to filter the results with field "test" and value "ghij".



PUT /test_index
{
"settings": {
"index": {
"number_of_shards": 4,
"number_of_replicas": 1,
"refresh_interval": "60s",
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "my_snow"]
},
"blogs_analyzer": {
"type": "stop",
"stopwords": "_english_"
}
} ,


"filter" : {
"my_snow" : {
"type" : "snowball",
"language" : "Lovins"
}
}
}
}
},
"mappings": {
"doc": {
"_source": {
"enabled": true
},
"properties": {
"content": {
"type": "text",
"index": "true",
"store": true,
"analyzer":"my_analyzer",
"search_analyzer": "my_analyzer"
},
"host": {
"type": "keyword",
"index": "true",
"store": true

},
"title": {
"type": "text",
"index": "true",
"store": true,
"analyzer":"my_analyzer",
"search_analyzer": "my_analyzer"

},
"url": {
"type": "text",
"index": "true",
"store": true

},
"test": {
"type": "keyword",
"index": "true",
"store": true
}

}
}
}
}


I tried with the below body in order to get the results.



POST test_index/_search
{
"query": {
"bool": {
"should": [{
"match": {
"content": {
"query": "sports"

}
}
},
{
"match": {
"title": {
"query": "sports"

}
}
}
],
"filter": {
"bool": {
"must": [{
"term": {
"test": "ghij"
}
}]
}
}
}
}
}


If I send the above request I am getting lesser records and I use send direct request GET /test_index/_search?q=sports I am getting more number of results







elasticsearch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 15:22









an__snatcher

548




548












  • The direct request queries every field in your documents while the book query restricts to just two so this is as expected if the term sports will exist in all the fields
    – ookboy24
    Nov 9 at 16:29










  • Hey @an__snatcher , the query you've posted works as expected. May I know what is it you are looking for and what is it that you are not observing? If you can update some sample documents in the question that would help us to help you. :)
    – Kamal
    Nov 9 at 18:07


















  • The direct request queries every field in your documents while the book query restricts to just two so this is as expected if the term sports will exist in all the fields
    – ookboy24
    Nov 9 at 16:29










  • Hey @an__snatcher , the query you've posted works as expected. May I know what is it you are looking for and what is it that you are not observing? If you can update some sample documents in the question that would help us to help you. :)
    – Kamal
    Nov 9 at 18:07
















The direct request queries every field in your documents while the book query restricts to just two so this is as expected if the term sports will exist in all the fields
– ookboy24
Nov 9 at 16:29




The direct request queries every field in your documents while the book query restricts to just two so this is as expected if the term sports will exist in all the fields
– ookboy24
Nov 9 at 16:29












Hey @an__snatcher , the query you've posted works as expected. May I know what is it you are looking for and what is it that you are not observing? If you can update some sample documents in the question that would help us to help you. :)
– Kamal
Nov 9 at 18:07




Hey @an__snatcher , the query you've posted works as expected. May I know what is it you are looking for and what is it that you are not observing? If you can update some sample documents in the question that would help us to help you. :)
– Kamal
Nov 9 at 18:07

















active

oldest

votes











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',
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228559%2funable-to-get-similar-results-with-a-filter-applied-specific-field%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228559%2funable-to-get-similar-results-with-a-filter-applied-specific-field%23new-answer', 'question_page');
}
);

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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()