MultiMatch query with Nest and Field Suffix

1.8k views Asked by At

Using Elasticsearch I have a field with a suffix - string field with a .english suffix with an english analyser on it as shown in the following mapping

...
"valueString": {
    "type": "string",
    "fields": {
        "english": {
             "type": "string",
             "analyzer": "english"
        }
    }
}
...

The following query snippet won't compile because ValueString has no English property.

...
sh => sh
    .Nested(n => n
        .Path(p => p.ScreenData)
            .Query(nq => nq
                .MultiMatch(mm => mm
                    .Query(searchPhrase)
                    .OnFields(
                        f => f.ScreenData.First().ValueString,
                        f => f.ScreenData.First().ValueString.english)
                    .Type(TextQueryType.BestFields)
                )
            )
        )...

Is there a way to strongly type the suffix at query time in NEST or do I have to use magic strings?

1

There are 1 answers

1
Rob On BEST ANSWER

Did you try to use extension method Suffix?

This is how you can modify your query:

...
.OnFields(
    f => f.ScreenData.First().ValueString,
    f => f.ScreenData.First().ValueString.Suffix("english"))
.Type(TextQueryType.BestFields)
...

Hope it helps.