How to define a Terms query with the typed client?

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser): 3.9

Describe the issue:

Hey there, I’m using opensearch-go and relying heavily on the typed client usage. In trying to define a terms query, I’ve hit a wall, as I’m not quite sure how to simply match on a single field for multiple values.

For a singular term query, it looks like this works:

q := &opensearchapi.CommonQueryDSLQueryContainer{}
q.Term = make(map[string]opensearchapi.CommonQueryDSLTermQuery)
q.Term[fieldName] = opensearchapi.NewCommonQueryDSLTermQueryFromValue(opensearchapi.CommonQueryDSLTermQueryValue{Value: &fieldValue})

But I’m stumped as to how the Terms field on the CommonQueryDSLQueryContainer works. It doesn’t appear to have any way to specify a field name and then the set of values to match? For example, it does not appear to have any equivalent *FromValue() method?

Does anyone have an example of how it should be used?

I suppose at worst, I can just define multiple singlular Term queries each with the different values?

Cheers!

The Terms field works the same way as your Term example. It is a map keyed by field name, but each entry holds the whole list of values for that field instead of a single value, so build it the same way you built q.Term, just with the values list for the field. I am not 100% sure of the exact constructor name in 3.9, but the map keyed by field name is the part to get right.

Hey yeah that’s what I thought! But it looks like the CommonQueryDSLTermsQuery is missing those fields. I ended up filing a bug report about it:

I was initially unsure whether I was just misreading the code, but I’m pretty sure there is a bug now.