N
N
nicolaa2020-12-14 12:53:45
elasticsearch
nicolaa, 2020-12-14 12:53:45

How to check if a field exists in a document with an AND operator?

There is a normal search, where we search by `category_id` and the existence of the `fields.id` characteristic

"query" => [
      "bool" => [
        "must" => [
          "match" => [
            "category_id" => $category_id
          ], [
            "exists" => [ 
              "field" => "fields.$id"
            ]
          ]
        ]
      ]
    ]

The search works, the task was to add another check for the existence of the `fields.id` feature, but in order for it to have an `AND` operator, that is, you need to get all the products where:

Category `= 1`
There is a feature with `id = 1`
OR there is a characteristic with `id =2`

In the documentation, I found the possibility of choosing an operator, only for `match`

"match" => [
      "message" => [
        "query": "this is a test",
        "operator": "or"
      ]
    ]


Is there a similar solution for `exists`

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question