0

I know I can do a nested path search when I want to search for just one value using the following code:

    .Query(q => q
        .Nested(n => n
            .Path(p => p.memberships)
                .Query(q2 => q2
                .Bool(b => b
                    .Should(s2 => s2
                        .Match(m => m.Field("memberships.Id").Query("20334089"))))))))

That works fine. I am trying to do a query based off of a list of strings as the field values. I am using this TermAny function based off this previous answer and thought it may have worked with this for a nested path query:

https://stackoverflow.com/a/36377068/1451776

private static QueryContainer TermAny<T>(QueryContainerDescriptor<T> descriptor, Field field, object[] values) where T : class
{
    QueryContainer q = new QueryContainer();
    foreach (var value in values)
    {
        q |= descriptor.Term(t => t.Field(field).Value(value));
    }
    return q;
}

Let's say I have a list of Ids in a string array myIDSArry and I want to use that to search in a nested path field called memberships in elasticsearch. I have tried this

    .Query(q => q
        .Nested(n => n
            .Path(p => p.memberships)
                .Query(q2 => q2
                    .Bool(b => b
                        .Should(s => TermAny(s, "memberships.Id", myIDSArry)))))))

However it comes back as 0 hits and I know there should be some in the results. Any ideas on how I can use this based off a list of strings to search?

1 Answer 1

0

Actually I found the answer and am posting it in case others have the same question. Its pretty simple based off what I know in querying in elasticsearch, the word "keyword" I know is used sometimes. I fixed it by adding .keyword

.Query(q => q
        .Nested(n => n
            .Path(p => p.memberships)
                .Query(q2 => q2
                    .Bool(b => b
                        .Should(s => TermAny(s, "memberships.Id.keyword", myIDSArry)))))))
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.