我遇到这个问题:当我尝试过滤它们时,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/