Using a Terms Query via Elastic.Clients.Elasticsearch 8.1.1 .NET

Hi, @felix-stnr.

You raise a great example of where our code generated APIs could be improved. I'll open an issue to track work to make this easier to achieve.

It's quite verbose but you can create it like this for now:

var companyIds = new long[] { 1, 2, 3 };
var response = await client.SearchAsync<Person>(s => s
	.Index("persons")
	.Query(q => q
		.Bool(b => b
			.Must(m => m
				.Terms(ts => ts
					.Field("companyId")
					.Terms(new Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryField(companyIds.Select(id => FieldValue.Long(id)).ToArray()))
				)
			)
		)
	)
);
1 Like