Query DSL, multiple filter, dynamic query

Hey,

I have to create dynamic query to be more precise, create multiple filters, here's my code :

Filter dynamic creation :

var filters = new List<Func<QueryContainerDescriptor<Source>, QueryContainer>>();
for (int i = 0; i < nbPoint; i++)
{
    filters.Add(
                    mu => mu.GeoBoundingBox(ge => ge
                            .Field(f => f.End)
                            .BoundingBox(latLeftTab[i], lonLeftTab[i], latRightTab[i], lonRightTab[i])
                        ) && mu
                        .GeoBoundingBox(ge => ge
                            .Field(f => f.Start)
                            .BoundingBox(latLeftTab[i], lonLeftTab[i], latRightTab[i], lonRightTab[i])
                        ) || mu
                        .GeoBoundingBox(ge => ge
                            .Field(f => f.End)
                            .BoundingBox(latLeftTab2[i], lonLeftTab2[i], latRightTab2[i], lonRightTab2[i])
                        ) && mu
                        .GeoBoundingBox(ge => ge
                            .Field(f => f.Start)
                            .BoundingBox(latLeftTab2[i], lonLeftTab2[i], latRightTab2[i], lonRightTab2[i])
                        )

    );
}

My request :

var searchResponse = client.LowLevel.Search<StringResponse>("jam", "jam", PostData.Serializable(new SearchDescriptor<Source>()
                 .From(0)
                 .Size(size)
                 .Query(q => q
                     .Bool(b => b
                         .Must(fi => fi
                             .DateRange(r => r
                                 .Field(f => f.Timestamp)
                                 .GreaterThanOrEquals(limitDate)
                                 .LessThan(DateTime.Now)
                             ), mi => mi
                         )
                         .Filter(filters)
                          
                         )
                     )
                 ));
                 qJson = searchResponse.Body;

Only the last filter in my loop is taken

Here is what I answered in Créer des filtres dynamiques pour requête QSL, NEST

I don't know a lot about Nest but I believe you should write something like:

filters.Add(/* one single GeoBoundingBox */);
filters.Add(/* one single GeoBoundingBox */);
filters.Add(/* one single GeoBoundingBox */);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.