ElasticSearch - 范围查询无效

时间:2016-03-13 12:51:08

标签: php elasticsearch

我是ElasticSearch的新手,很抱歉,如果这是noob问题。我正在努力让那些薪水低于某些价值的用户得到这个错误:

query_parsing_exception: No query registered for [salary] 

我的其他查询工作正常,只有range query失败,这是我的代码:

$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,
    ]
]);

如果我删除范围查询然后一切正常,我也检查索引值和工资是否(整数)。 感谢

1 个答案:

答案 0 :(得分:1)

查询不是有效的DSL。特别是你在must子句中缺少一堆括号。 bool查询中的must应该是一个子句数组,而在上面它是一个带有键matchrange的对象。

示例:

$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,
    ]
]);