Answer the question
In order to leave comments, you need to log in
How to search by nested in elasticsearch?
there are Users they have an array of eDates:
"eDates" : [
{
"dateFrom" : ISODate("2017-04-01T12:33:50.000+0000"),
"dateTo" : ISODate("2017-04-05T12:33:50.000+0000"),
"_id" : ObjectId("58c2ab50875060766968d41d")
},
{
"dateFrom" : ISODate("2017-10-01T12:34:04.000+0000"),
"dateTo" : ISODate("2017-10-07T12:34:04.000+0000"),
"_id" : ObjectId("58c2ab50875060766968d41c")
}, ...
],
let nested = []
let from = {"range" : {"eDates.dateFrom" : {"gt": new Date(data.dateFrom)} }};
let to = {"range" : {"eDates.dateTo" : {"lt": new Date(data.dateTo)} }};
nested.push(from, to);
"filter": {
"nested" : {
"path" : "eDates",
"query" : {
"bool" : {
"must" : nested
}
}
}
}
Answer the question
In order to leave comments, you need to log in
The problem is that in the usual order, an array of objects is mapped into one object when indexed.
That's why he finds it.
What would be looking for as you want - you need to change the mapping.
https://www.elastic.co/guide/en/elasticsearch/guid...
https://www.elastic.co/guide/en/elasticsearch/guid...
https://www.elastic.co/ guide/en/elasticsearch/refe...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question