Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch multiple range error

I have a problem with Elasticsearch

The following json values work in my local server but not in the remote server.

ERROR:query doesn't support multiple fields, found [date] and [price]

post.json

{
            "query": {
                "bool": {
                    "must": [
                        {
                            "query_string": {
                                "query": "product:DESKTOP"
                            }
                        },
                        {
                            "range": {
                                "date": {
                                    "gt": "2018-04-24",
                                    "lte": "2018-06-24"
                                },
                                "price": {
                                    "gt": 0,
                                    "lte": 2000
                                }
                            }
                        }
                    ]
                }
            },
            "from": 10,
            "size": 200         }

Where do I mistake? Thank you for answers

like image 744
ercvs Avatar asked Sep 01 '25 04:09

ercvs


1 Answers

You can only specify one field per range query.

Try including two separate range queries. They'll be AND'd together, since they both show up in your must clause.

{
    "query": {
        "bool": {
            "must": [
                {
                    "query_string": {
                        "query": "product:DESKTOP"
                    }
                },
                {
                    "range": {
                        "date": {
                            "gt": "2018-04-24",
                            "lte": "2018-06-24"
                        }
                    }
                },
                {
                    "range": {
                        "price": {
                            "gt": 0,
                            "lte": 2000
                        }
                    }
                }
            ]
        }
    },
    "from": 10,
    "size": 200
}
like image 160
Matthew Haugen Avatar answered Sep 02 '25 18:09

Matthew Haugen