gpt4 book ai didi

node.js - ElasticSearch JS查询返回所有文档而不是过滤

转载 作者:行者123 更新时间:2023-12-03 00:59:52 27 4
gpt4 key购买 nike

我遇到这个问题:当我尝试过滤它们时,ElasticSearch JS返回所有文档。我有两个文档,只有一个与这些过滤器匹配,但是ES返回所有文档...没有创建映射,只有两个文档。我不知道该怎么办...

我正在使用Node JS

  client.search({
index: "yojuego",
type: "user",
query: {
"filtered": {
"filter": {
"bool": {
"must": [
{ "term": { "userid": "123456789" } },
{ "term": { "type": "yojuego" } }
]
}
}
}
}
}, (error, response, status) => {
if (error) {
res.json(400, err);
}
else {
res.json(200, response.hits.hits);
}
});
});

最佳答案

您的搜索参数中有一个错字,您需要将query括在body参数中。

  client.search({
index: "yojuego",
type: "user",
body: { <--- add this
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{ "term": { "userid": "123456789" } },
{ "term": { "type": "yojuego" } }
]
}
}
}
}
}
}, (error, response, status) => {
if (error) {
res.json(400, err);
}
else {
res.json(200, response.hits.hits);
}
});
});

关于node.js - ElasticSearch JS查询返回所有文档而不是过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39502026/

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