R
R
Ruslan2018-01-18 19:40:11
elasticsearch
Ruslan, 2018-01-18 19:40:11

What's wrong with Elasticsearch filters?

The version of elasticsearch is 6.0.0
for such a request:

{
  "size": 50,
  "query": {
    "bool": {
      "must": {
        "wildcard": {
          "keywords": {
            "value": "*chero*",
            "boost": 2
          }
        }
      },
      "filter": {
        "terms": {
          "category_id": [33, 35]
        },
        "range": {
          "access_index": {"lte": 10}
        }
      }
    }
  }
}

I get the answer [terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]
one of the filters should be removed
"terms": {
          "category_id": [33, 35]
        },

"range": {
          "access_index": {"lte": 10}
        }

then everything is searched as it should...
how to correctly use both filters in conjunction AND
looked here: https://www.elastic.co/guide/en/elasticsearch/refe...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan, 2018-01-19
@Tiasar

This is how it works on elasticsearch version 6.0.0

{
  "query": { 
    "bool": { 
      "must": {
        "wildcard": {
          "keywords": {
            "value": "автобус*",
            "boost":2
          }
        }
      },
      "filter": [ 
        { "terms":  { "category_id": [33, 35] }}, 
        { "range": { "access_index": { "lte": 30 }}} 
      ]
    }
  }
}

A
Alexey Cheremisin, 2018-01-18
@leahch

Wrap both filters in bool, and only then insert them into the filter itself

...
     filter
          bool
               must
                   terms
                   range

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question