0

I'm having trouble adding nested fields to a text index in MongoDB.

The code below adds string fields at the top level to the text index correctly. The two nested fields "contentright" and "contentfooterhead" that I am trying to add are added but do not index correctly.

enter image description here

var keys = {"name", "subject", "contentright", "contentfooterhead"};

var indexKeys = new IndexKeysBuilder();
indexKeys.Text(keys);

var options = new IndexOptionsBuilder();
options.SetName("testIndex");
options.SetBackground(true);

collection.CreateIndex(indexKeys, options);

This is what my text index looks like after the code is run:

enter image description here

If I run

indexKeys.TextAll();

which is equivalent to an index of

"$**": "text"

all the fields are indexed fine, but I don't want to add them all.

1 Answer 1

1

Use dot notation. The paths to your nested fields are Con.contentright and Con.contentfooterhead.

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.