Skip to content

Feature request to add back || and &&. Or to allow for dynamic building and joining of queries #8342

@JonathonFord

Description

@JonathonFord

Is your feature request related to a problem? Please describe.
I need to build a query based on user input. Basically I want to generate something like this:
GET elasticIndexExample/_search { "query": { "bool":{ "must": [ { "range": { "creationDate": { "gte": "2004-08-02T05:00:00.000Z", "lte": "2004-10-02T05:00:00.000Z", "boost": 2.0 } } }, { "bool":{ "should": [ { "term":{ "customerName": "Wallmart" } }, { "term":{ "customerName": "Petco" } } ], "minimum_should_match": 1 } }, { "bool": { "should": [ { "term":{ "state": "OH" } }, { "term":{ "state": "MI" } } ], "minimum_should_match": 1 } } ] } } }
This query works for what I need. Also each should array doesn't HAVE to be there.

Describe the solution you'd like
I would like to be able to build the should arrays like this for the should arrays:
customerNameShouldQuery.Bool(boolQuery => boolQuery.Should(should => { foreach (var customerName in customerNameArray) { should.AddTerm(term => term.Field(field => field.CustomerName).Value(customerName) ); } }) .MinimumShouldMatch(1) );
Describe alternatives you've considered
The old way of using || to build a should array of term matches is ok, tho I cant set the minimum should match easily
var test = new QueryContainer(); foreach (var customerPO in customerPOs) { test = test || new QueryContainerDescriptor<ElasticLoad>().Term(term => term.CustomerPO, customerPO); }
Additional context
At the very least I dont know how to go about building a should array in the new version 8 off of an array of inputs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions