Using bool must match and match _all in one elasticsearch query

baskax

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.

Ohlsen1980

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.

edited at
0

Comments

0 comments
Login to comment

Related

What is difference between match and bool must match query in Elasticsearch

Elasticsearch [Query Bool Must Match] performs OR operation instead of AND

Elasticsearch match all query using Java API

In elasticsearch, must match one of array, with optional extra query term

Elasticsearch query match one word

Diference between term and match in Elasticsearch in a bool query

Elasticsearch How to add bool query inside must_not with multiple match in java API?

must match query not working as expected in Elasticsearch

Elasticsearch query must not match text from field

ElasticSearch query using Nest - Match Field to one of a few options

How to search for query in all fields in match using elasticsearch

Why is ElasticSearch match query returning all results?

elasticsearch bool query combine must with OR

Elasticsearch search bool + must query

Elasticsearch must_not query doesn't match regex

ElasticSearch with multi_match AND bool

ElasticSearch: Using match_phrase for all fields

"match or null" query in elasticsearch

Query to match substrings in elasticsearch

ElasticSearch: is bool-must-term(3) equivalent to old terms with minimum_should_match 3

elasticsearch match all words from document in the search query

Query Firestore data and add one field to all the documents that match the query

Error: Content of 'all' must match

How to query using a range and match under a must clause?

Join tables using IN clause where must match ALL values

@Query match _all function

Elasticsearch difference between MUST and SHOULD bool query

Min_score for a "must" in a bool query in Elasticsearch

Elasticsearch query not giving exact match