I am using Atlas full test search, the problem is that “queryString” do search in whole collection.
then return the match documents, I want to first filter by date then perform the queryString.
BR,
Shahnawaz
I am using Atlas full test search, the problem is that “queryString” do search in whole collection.
then return the match documents, I want to first filter by date then perform the queryString.
BR,
Shahnawaz
Hi @Shahnawaz_Haider1 , you can use the $search compound
operator to combine search criteria like so:
filter
clause with the range
operator on the date fieldmust
clause with queryString
to specify your full text search {
"$search": {
"compound": {
"filter": [{
"range": {
"gt": ISODate(),
"path": <date_path>
}
}],
"must": [{
"queryString": {
"query": <query>,
"defaultPath": <path>
}
}]
}
}
}
])
This should allow you to get the results you are looking for.
Dear Amy,
Thank you so much for your reply.
Its working fine for me.
Thanks a ton!
BR,
Shahnawaz
Hi,
Is it possible to use “slop” with queryString.
BR,
Shahnawaz
@Shahnawaz_Haider1 , yes, you can do so by using the ~
option, see the Note under queryString > Options > query > ~
Please ensure that you are 1) putting the phrase in double quotes, 2) escaping the double quotes with \
{
... "$search": {
... "queryString": {
... "defaultPath": "plot",
... "query": "\"my phrase query\"~1",
... }
... }
... }
In the above example, slop is set to 1.
Is it possible to find the total match of search string?
@Shahnawaz_Haider1 , if you are looking for an exact match on a string, I recommend using the token
field mapping and the equals
or in
operator.