It's my first attempt to use elasticsearch and I'm trying to get all documents that must match given param and use match _all field at once. My schema looks like this
{
"mappings":{
"product":{
"_all":{"enabled":true},
"properties":{
"category":{"type":"text"},
"brand":{"type":"text"},
"model":{"type":"text"},
"description":{"type":"text"}
}
}
}
}
So let's say I want to find all products that are exactly of category "phone" and there is word "perfect" in any property. I don't have any problems with using only
_search
"query": {
"match": {
"_all": "perfect"
}
}
but I can't find a solution for combining it with matching the category at the same time. What is the best way to achieve this? If that matters I'm using official elasticsearch node.js plugin.
You have to use bool query - here you can combine more properties, which can be searched. See elasticsearch documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
Here is the example from doc:
GET _search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"term": {
"status": "active"
}
}
}
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments