1

I am trying to perform a search over an index for the following object:

public class IndexedElement
{

    public Guid Id { get; set; }
    public long RowId { get; set; }
    public IndexedElementType Type { get; set; }
    public string Summary { get; set; }
    public string Description { get; set; }

    public IList<string> Tags { get; set; }

}

The purpose is to search by the Summary property, or by matching any of the strings inside the Tags collections

What I currently have is this:

    public IEnumerable<IndexedElement> Search(string description)
    {
        var query = GetClient().Search<IndexedElement>(s => s.From(0).Size(5)
            .Query(
                q => q.Term(p => p.Summary, description)
                ||
                q.Nested(n => n.Path(p => p.Tags).Query(q2 => q2.Terms(t => t.Field(f => f.Tags).Terms(description))))                    
            ));

        return query.Documents.ToList();
    }

But the Nested part is not working, I don't know if I am using it in the proper way or maybe I have to find another solution for that.

Any ideas?

Thank you all in advance

1 Answer 1

1

You don't need to perform a nested query to query the Tags field, as each tag is only a primitive JSON value i.e. a string. Just the terms query will suffice.

Where a nested query would be needed is where Tags is a POCO with multiple properties and is mapped as a nested datatype.

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.