0

Have an ElasticSearch index where the potential hits are build like this:

id: number,
source: string,
type: string,
organization: {
    main: [string],
    support: [string]
},
title: {
    main: [string],
    sub: [string]
}

My problem is that I can't search the elements in [].

No problem doing this:

var searchResults = client.Search<Document>(s => s
                .Index(****)
                .Type(****)
                .MatchAll()
                .Query(q =>
                    q.Term(p => p.source, "some source name")
                ))

But this one doesn't work:

var searchResults = client.Search<Document>(s => s
                .Index(****)
                .Type(****)
                .MatchAll()
                .Query(q =>
                    q.Term(p => p.organization.main[0], "some organization name")
                ))

I have also tried this version, but it also doesn't work:

var searchResults = client.Search<Document>(s => s
                .Index(****)
                .Type(****)
                .MatchAll()
                .Query(q =>
                    q.Term(p => p.organization.main, "some organization name")
                ))

Can anyone spot what is going wrong?

1
  • May you share index mapping? Commented Oct 28, 2016 at 14:02

1 Answer 1

2

You can use LINQ's .First() extension method to reference the "organization.main" field in Elasticsearch

var searchResults = client.Search<Document>(s => s
    .Index(****)
    .Type(****)
    .MatchAll()
    .Query(q =>
        q.Term(p => p.organization.main.First(), "some organization name")
    )
 );

Bear in mind that your query is operating over the whole array here, not the first item in organization.main as the usage of .First() might imply. Arrays are indexed as multi value fields which are unordered. They come back ordered in the _source however.

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.