ElasticSearch JS查询返回所有文档,而不是过滤 [英] ElasticSearch JS query returns all document instead of filtered
本文介绍了ElasticSearch JS查询返回所有文档,而不是过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个问题:ElasticSearch JS返回所有文档,当我尝试过滤它们。我有两个文档,只有一个与这些过滤器匹配,但ES返回所有文档...没有创建映射,只创建了两个文档。我不知道该怎么办...
i am with this problem: ElasticSearch JS returns all documents when I try to filter them. I have two documents, only one that match with those filters, however ES returns all documents... There is no mappings created, only two documents created. I dont know what to do...
我正在使用Node JS
I'm using 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);
}
});
});
推荐答案
你的搜索参数有错字,你需要将查询
包含到正文
参数中。
You have a typo in your search parameters, you need to enclose your query
into the body
parameter.
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);
}
});
});
这篇关于ElasticSearch JS查询返回所有文档,而不是过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文