Elasticsearch, Nest Query to filter documents on fallback approach

18 views Asked by At

Here is what i want to achieve: "For the documents with same parent_id, get not more than 1 document whose "doc_language" field contains "langCode", if not found, fallback to get 1 document with "doc_language" as "EN", if not found, fallback to get 1 document with "doc_language" as "DE", else get any 1 document from that group"

i had written the following query but this doesn't seem to work:

searchDescriptor.Aggregations(aggs => aggs
         .Terms("parentID_group", term => term
             .Field(f => f.parent_id)
             )
     );
 searchDescriptor.Query(q => q
                            .Bool(b => b
                               .Should(
                                   s => s.Wildcard(w => w.Field(f => f.ropa_document_language).Value($"*{langCode}*")),
                                   s => s.Wildcard(w => w.Field(f => f.ropa_document_language).Value($"*EN*")),
                                   s => s.Wildcard(w => w.Field(f => f.ropa_document_language).Value($"*DE*"))
                               )
                           )
                        );
0

There are 0 answers