We are trying to migrate our existing Elastic Search (Kibana) queries into Mongo and I need to do something like this in mongo…
{
$search : {
index: ‘default’,
“compound”:{
"filter": [{
… some filter clauses…
}],
“should”: [{
“text”: {
“query”:<date range clause like “lte than now”>,
“path”: “”,
“score”: { “boost”: { “value”: 100 }}
}
},
{
“text”: {
“query”:<date range clause like “gte than now-7d”>,
“path”: “<date field-1(on the same date field as above)>”,
“score”: { “boost”: { “value”: }}
}
},
{
“text”: {
“query”:<date range clause similar to the 2 above>,
“path”: “<date field-2 (just any different field )>”,
“score”: { “boost”: { “value”: }}
}
},
.....other "text" clauses searching on string data type....
]
}
}
}
Problems I have faced with different approaches I have taken are (feel free to correct me on any of the below):
- Search can not be second stage of an aggregation pipeline so I can’t perform filters under $match or a $Range query.
- $Range doesn’t support querying same field with different boost score .
- Compound clause within Search could have been a good choice but it doesn’t support Date queries.
Please help what should I do!