0

Hi I am trying to create a text index in mongodb compass.

It gives me the following error:

Index build failed: 37ecddaa-47ae-4dc4-928e-2af83156fb10: Collection test.commerceProduct ( 9dc03ec5-cda1-4b61-8245-04d085846dbe ) :: caused by :: found language override field in document with non-string type

I am creating it on name field.

The values in name are not null neither empty, they are of string type.

If someone can please help.

4
  • Please check - stackoverflow.com/questions/27179664/… Commented Jan 28, 2022 at 4:44
  • okay, great !!! Commented Jan 28, 2022 at 10:56
  • Hi, one more thing, There are five fields in my collection that I need to query for my application, three of them are strings and remaining two are list of strings. without indexing the query runs in 650ms. I am creating the text indexes on all five of fields (compound index) , the query optimiser in mongodb compass does not picks up this index for searching. The search type is of regex one. Also we cannot force it since it is of text type (regex). Lastly I created the sorted indexes on all fields individually, it works in about 1100 ms. I need it <500ms. Can you guide me on this ? Commented Jan 29, 2022 at 10:19
  • here is a bit of summary on it , I tried working with adding all text fields, the query selector does not uses them. I have tried adding them individually, as a text field, again the query selector does not uses them. Then I have tried adding them in regular manner (sorted), by adding all the fields individually, the query selector uses them, but the timing is about 1100 instead of 600. Also we cannot force the query to use the created index for execution , as from docs “You cannot use hint() if the query includes a $text query expression.” @Alokp Commented Jan 29, 2022 at 10:21

1 Answer 1

0

Click on the required collection to search and then navigate to index page. Now click on "Create Index" and select "Search Index" and further, click on "Search". Now, give a name to your search index such as "search_index" and write the following code in the input box:

{
  "mappings": {
    "dynamic": true,
    "fields": {
      "title": "text"
    }
  }
}

Keep in mind to replace the fields with your collection's respective fields that you want to enable the search on.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.