constant_score 查询不支持代码中的查询

A.C*_*Ran 3 node.js elasticsearch

当我尝试运行以下代码时,会出现“恒定分数查询不支持查询”错误。

client.search({
    index: ['index1','index2'],
    body: {
        from: 0, size: 20,
        query: {
            "constant_score": {
                boost: 1.0,
                "query": {
                    query_string: {
                        query: str,
                        fields: ['field_1']
                    }
                }
            }
        }
    },
});
Run Code Online (Sandbox Code Playgroud)

Nis*_*ini 5

constant_score查询包装另一个查询。它要么接受另一个queryfilter. 裹query_stringfilter代替query

尝试使用以下方法:

client.search({
    index: ['index1','index2'],
    body: {
        from: 0, size: 20,
        query: {
            "constant_score": {
                boost: 1.0,
                filter: {
                   query_string: {
                       query: str,
                       fields: ['field_1']
                   }
                }                
            }
        }
    },
});
Run Code Online (Sandbox Code Playgroud)