I'm attempting to create slightly more complex queries using Java API client 7.16 (like the json below), but I'm not sure which direction to go in to do this correctly. Do I use terms query for something like this query below, or do I add multiple terms to a query?
Also, it's difficult to navigate the docs for this version, so I can't find a way to even specify multiple terms via a list.
The below java code only works for "keyword" types, but doesn't work for any text fields - is there something I'm missing? I tried attaching an analyzer but the client threw some errors there.
My ideal scenario would be providing a map of queries { "textField1": "foo", "boolField1": "True", "intField1": "20", "keywordField1": "Af:5E:1b:D8", "obj1.name": "bar"}
and using the search response to fetch all the matching documents (note: the query could contain nested fields and non-nested fields). Does this exist? What is the best way to do something like this if it does not?
Thank you in advance.
SearchRequest sr = new SearchRequest.Builder()
.index("index")
.query(q -> q
.term(t -> t
.field("field1")
.value(v -> v.stringValue("foobar"))
)).build();
{
"bool":{
"must":[
{"match": {"textField1": "foo"}},
{"match": {"boolField1": True}},
{"match": {"intField1": 20}},
{"match": {"keywordField1": "Af:5E:1b:D8"}},
{
"nested": {
"path": "obj1",
"query": {
"bool": {
"must": [
{ "match": { "obj1.name": "bar" } }
]
}
}
}
}
]
}
}