U
U
un1t2015-10-20 09:44:40
elasticsearch
un1t, 2015-10-20 09:44:40

Why does the range filter in Elasticsearch consume more resources than full-text search?

I have filtered query.
In the first case, the search occurs in the text,

{ 'query': {'filtered': {'filter': {'bool': {'must': [{'term': {'status': 4}}]}},
                        'query': {'bool': {'should': [{'match': {'name': {'operator': 'and',
                                                                          'query': 'барменша'}}},
                                                      {'match': {'description': {'boost': 0.9,
                                                                                 'operator': 'and',
                                                                                 'query': 'барменша'}}},
                                                      {'match': {'author': {'boost': 0.8,
                                                                            'operator': 'and',
                                                                            'query': 'барменша'}}},
                                                      {'match': {'tags': {'boost': 0.7,
                                                                          'operator': 'and',
                                                                          'query': 'барменша'}}}]}}}}

In the second case, a range filter is used.
{
 'query': {'filtered': {'filter': {'bool': {'must': [{'term': {'status': 4}},
                                                     {'range': {'year_to': {'lte': '1946'}}}]}}}}

The complete surprise is that the second request loads the processor 2 times more. Why is that? How to fix?
Mapping looks like this:
"properties": {
    "id": {
        "type": "integer"
    },
    "name": {
        "analyzer": "russian_morphology",
        "type": "string"
    },
    "description": {
        "analyzer": "russian_morphology",
        "type": "string"
    },
    "status": {
        "type": "integer"
    },
    "tags": {
        "analyzer": "russian_morphology",
        "type": "string"
    },
    "year_from": {
        "type": "integer"
    },
    "year_to": {
        "type": "integer"
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kotofey, 2015-10-20
@kotofey

I'm confused by the way your request is framed. Try like this:

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "status": "4"
          }
        },
        {
          "range": {
            "year_to": {
              "from": "1946"
            }
          }
        }
      ],
      "must_not": [ ],
      "should": [ ]
    }
  },
  "from": 0,
  "size": 10
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question