I want to search “Marketing in social networks” inside documents. All together. But i continue getting results with words separated. i have the following DSL query:
{
"fields": ["title"],
"query": {
"bool": {
"should": [{
"match": {
"title": "SEO"
}
}],
"must": [{
"match": {
"content": {
"query": "Marketing in social networks",
"operator": "and"
}
}
}]
}
}
}
I do not have documents that contain this phrase and title but i also get results(documents) with the words of the phrase to search splitted. I want a strict search. If there is not any document that have this phrase do not retrieve any document or only retrieve documents with that title.
Why operator and does not work?
2
Answers
Can you try like below using type phrase. See here it says,
P.S: I haven’t tried it yet.
First answer is good but for ES v5 using
"type":"phrase"
will return[WARN ][org.elasticsearch.deprecation.common.ParseField] Deprecated field [type] used, replaced by [match_phrase and match_phrase_prefix query]
in the headersSo correct query should contain match_phrase: