Elasticsearch错误:[parsing
我遇到了elasticsearch npm模块的问题。这是我的查询:
try {
const {
hits: { hits }
} = await client.search({
index: "articles",
body: {
query: {
match_phrase: {
authors: {
first_name: firstName,
last_name: lastName
}
}
}
}
});
hits.forEach(hit => {
hit.type = TYPE_PHRASE;
});
return hits;
} catch (err) {
但是这将返回错误,
Error: [parsing_exception] [match_phrase] query does not support [first_name]
我不确定这是什么意思。这是否意味着我无法通过first_name
进行搜索?
这是elasticsearch结构:
[
{
"_score": 10.8702135,
"_source": {
"title": "Some title",
"authors": [
{
"first_name": "John",
"last_name": "Smith",
},
{
"first_name": "Jane",
"last_name": "Doe",
},
回答如下:Match_phrase适用于单个字段。要搜索多个字段,请使用must / bool子句组合多个match_phrase子句。
query: {
bool: {
must: [
{
match_phrase: {
authors.first_name: firstName
}
},
{
match_phrase: {
authors.last_name: lastName
}
},
]
}
}