我遇到这个问题:当我尝试过滤它们时,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);
}
});
});
答案 0 :(得分:2)
您的搜索参数中有拼写错误,您需要将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);
}
});
});