Reputation: 3866
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...
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);
}
});
});
Upvotes: 0
Views: 1619
Reputation: 217424
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);
}
});
});
Upvotes: 2