Reputation: 131
Worked on Elastic Search 6.4.2. I want to use match_pharse
to get the retrieve the results from my index. In the same way I need to apply the filter for that. Any solution for this. I tried the below query
{
"query": {
"bool": {
"should":
{
"match_phrase": {
"title": "bike riding"
}}
}
}}
But When I using match_pharse
I need to pass the fields in order to get the results. I am sharing my mapping and query that I need to be edited. Any help that I can use the match_phrase
for a query.
Mapping:
{
"mapping": {
"doc": {
"properties": {
"content": {
"type": "text",
"store": true,
"analyzer": "my_analyzer"
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"domain": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"host": {
"type": "keyword",
"store": true
},
"keywords": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"seed": {
"type": "keyword",
"store": true
},
"title": {
"type": "text",
"store": true,
"analyzer": "my_analyzer"
},
"url": {
"type": "text",
"store": true
}
}
}
}
}`
Query:
How can I add match_phrase
to the below one
{
"query": {
"bool" : {
"must" : {
"query_string" : {
"query" : "bike riding"
}
},
"filter" : {
"term" : { "seed" : "sports" }
}
}
}
}
Upvotes: 1
Views: 513
Reputation: 8840
Below query is what you would be looking for.
Notice how I've added quotes around "\"bike riding\""
POST <your_index_name>/_search
{
"query": {
"bool" : {
"must" : {
"query_string" : {
"query" : "\"bike riding\""
}
},
"filter" : {
"term" : { "seed": "sports" }
}
}
}
}
Let me know if it helps!
Upvotes: 1