gpt4 book ai didi

node.js - Elasticsearch错误: [parsing_exception] [match_phrase] query does not support [first_name]

转载 作者:太空宇宙 更新时间:2023-11-03 23:13:35 26 4
gpt4 key购买 nike

我遇到了 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
}
},
]
}
}

关于node.js - Elasticsearch错误: [parsing_exception] [match_phrase] query does not support [first_name],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58348216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com