B
B
beb592020-05-28 14:57:01
elasticsearch
beb59, 2020-05-28 14:57:01

Why doesn't elasticsearch filter by range?

Good afternoon

, elastic search works very strangely, it does not filter or filters crookedly by range I
filter by the price field, integer type

This query returns 1 record

{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "price": {
              "gte": 100,
              "lte" : 10000000
            }
          }
        }
      ]
    }
  }
}


returns
{
    "took": 3,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.0,
        "hits": [
            {
                "_index": "indexsearchj",
                "_type": "_doc",
                "_id": "4064",
                "_score": 0.0,
                "_source": {
                    "name": "Раз два три",
                    "id": 4064,
                    "id_category": 1,
                    "price": 100000,
                    "is_my": 1,
                    "business_type": "3",
                    "area": "1123",
                    "property-type": "1",
                    "itemType": "2",
                    "metro": "18",
                    "metro-closest": "7"
                }
            }
        ]
    }
}


and this one is bigger
{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "price": {
              "gte": 100,
              "lte" : 6000000
            }
          }
        }
      ]
    }
  }
}


{
    "took": 5,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 12,
            "relation": "eq"
        },
        "max_score": 0.0,
        "hits": [
            {
                "_index": "indexsearch",
                "_type": "_doc",
                "_id": "1311",
                "_score": 0.0,
                "_source": {
                    "name": "",
                    "id": 1311,
                    "id_category": 1,
                    "price": 60000,
                    "is_my": 0,
                    "area": "40",
                    "property-type": "1",
                    "itemType": "2",
                    "business_type": "3",
                    "metro": "4",
                    "metro-closest": "8"
                }
            },


very strange behavior, and I don’t know where to look anymore

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
akelsey, 2020-05-29
@akelsey

Either filter or range (and, or), and you have filter { range }. I think the problem is this.
It should probably be like:

"query": {
    "range": {
      "price": {
        "gte": 100,
        "lte": 10000000
      }
    }
  }

B
beb59, 2020-06-01
@beb59

no, that doesn't work either

S
siri0s, 2021-03-18
@siri0s

At you requests go to different indexes. The first is in "indexsearchj", the second is in "indexsearch"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question