$text and $search in same aggregation pipeline

Hi All,
I am trying to query search index and text indexing in same query, as showing in picture below

But I am getting this error always

I tried changing the position of queries too, still error remains same.
Anyone help me and provide me a method how to implement both queries simultaneously.

Hi @Ashutosh_Mishra1 ,

The two operators (atlas text search and regular text search) are incompatible together.

You should be able to achieve everything with just atlas search stage,
.

Can you explain the requirements.

Thanks
Pavel

Hi @Pavel_Duchovny , Thanks for replying.
We have a fuzzy search index created to search for a field named “CompanyName”, and simultaneously we also want a textSearch index, to search through multiple fields namely, “technology”, “business”, etc. I want to get AND results of both the queries using single Atlas Aggregation pipeline.

Hi @Ashutosh_Mishra1 ,

You need a compound operator that has a text search on one field with fuzzy and then probably a filter clause on other fields:

db.collection.aggregate([
  {
    "$search": {
      "compound": {
        "must": [{
          "text": {
            "query": "company1",
            "path": "companyName"
          }
        }],
        
        "filter": [{
          "text": {
            "query": "bussnies1",
            "path": ["technology","business"]
          }
        }]
      }
    }
  }
])

You can see more variations and consideration when to add an end as “must” or when to use other filters. Filter does not affect score so its up to you how to use it properly.

Thanks
Pavel

We don’t need to metion respective indexes in queries? as we have different indexes for different fields in a collection.
image
Like we mention here

Hi @Ashutosh_Mishra1 ,

As far as I know it noy works with a single index in the same aggregation.

Why do you index on different indexes? Are the purpose different or its just been done that way?

Thanks
Pavel