简体   繁体   中英

ElasticSearch - Range query not working

I'm new to ElasticSearch so sorry if it's noob question. I'm trying to get users who has salary less than some value but I'm getting this error:

query_parsing_exception: No query registered for [salary] 

My other queries works fine, only range query is failing, this is my code:

$items = $this->client->search([
    'index' => 'offerprofiles',
    'type' => 'profile',
    'body' => [
        'query' => [
            'bool' => [
                "must" => [
                    "match" => [
                        "jobcategories.name" => [
                            "query" => $query['category']
                        ]
                    ],
                    "range" => [
                        "salary" => [
                            "lt" => 20
                        ]
                    ]
                ],
                "should" => [
                    "match" => [
                        "skills.name" => [
                            "query" => $query['skills']
                        ]
                    ]
                ],
                "minimum_should_match" => 1
            ]
        ],
        'size' => 50,
    ]
]);

If I remove range query then everything works fine, also I checked indexed values and salary is there (integer). Thanks

The query is not a valid DSL. In the particular you are missing a bunch of brackets in the must clause. The must in the bool query should be an array of clauses instead in the above it is an object with key match and range .

Example :

$items = $this->client->search([
    'index' => 'offerprofiles',
    'type' => 'profile',
    'body' => [
        'query' => [
            'bool' => [
                "must" => [
                 [
                    "match" => [
                        "jobcategories.name" => [
                            "query" => $query['category']
                        ]
                    ]
                 ],
                 [
                    "range" => [
                        "salary" => [
                            "lt" => 20
                        ]
                    ]
                 ]
                ],
                "should" => [
                    "match" => [
                        "skills.name" => [
                            "query" => $query['skills']
                        ]
                    ]
                ],
                "minimum_should_match" => 1
            ]
        ],
        'size' => 50,
    ]
]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM