One is to directly modify json string and use JsonGenerator.
The other is to create a helper class to build json string:
B4X:
Sub Process_Globals
End Sub
Sub stringToMap(jsonString As String) As Map
Log(jsonString)
Dim json As JSONParser
json.Initialize(jsonString)
Return json.NextObject
End Sub
Sub matchDict(field As String, queryString As String) As Map
Return CreateMap("match":CreateMap(field:queryString))
End Sub
Sub boolDict(boolType As String,conditions As List) As Map
Return CreateMap("bool":CreateMap(boolType:conditions))
End Sub
To use:
B4X:
Dim conditions As List
conditions.Initialize
conditions.Add(QueryDSLMaker.matchDict("text",text))
conditions.Add(QueryDSLMaker.matchDict("sourceOrTarget",sourceOrTarget))
Dim Query As Map
Query = QueryDSLMaker.boolDict("must",conditions)