JSON array with objects of different type

0
I am building a service to call AWS ElasticSearch. My JSON structure should like like the code below. The problem comes with the “filter” attribute. This attribute is an array of objects of different type: some are “bool”, others are “multi_match”. How should I model such structure?   {     "query": {         "bool": {             "must": [                 { "query_string": {                         "query": "ACME",                         "fields": ["AccountName","AccountNumber"]                   }                 }             ],             "filter": [                 {                     "bool": {                         "should": [                             { "multi_match": { "fields": ["Country"], "query": "US"} },                             { "multi_match": { "fields": ["Country"], "query": "CA"} }                         ]                     }                 },                 { "multi_match": {"fields": ["Status"],"query": "Active"}},                 { "multi_match": {"fields": ["BillToPrimary"],"query": "Y"}}             ]         }     },     "size": 100 }
asked
3 answers
3

I just built a Java action to do the job.

answered
1

Other solution would be to first build the json for the filter yourself in a microflow as a string and then use an export mapping? This, of course, needs some logic in your microflow but should be possible (with the modelreflection if needed).

 

answered
1

𝕺𝖈𝖐𝖊𝖗𝖙 𝖛𝖆𝖓 𝕾𝖈𝖍𝖆𝖑𝖐𝖜𝖞𝖐 you are pushing me :-) My complete JSON is below. It consists of four distinct parts: query (query.bool.must), domain (query.bool.filter.bool), facets (query.bool.filter.multi_match[]), and optional aggregation at the bottom. So, if I go the ExtractMapping route, I will need to build four extract maps and then do string massaging; the nasty one to marry domain and facets. Since I already wrote the Java action I was simply lazy enough to rewrite it using maps followed by inevitable string massaging.

{
    "query": {
        "bool": {
            "must": [
                { "query_string": {
                        "query": "ACME",
                        "fields": ["AccountName","AccountNumber"]
                  }
                }
            ],
            "filter": [
                {
                    "bool": {
                        "should": [
                            { "multi_match": { "fields": ["Country"], "query": "US"} },
                            { "multi_match": { "fields": ["Country"], "query": "CA"} }
                        ]
                    }
                },
                { "multi_match": {"fields": ["Status"],"query": "Active"}},
                { "multi_match": {"fields": ["BillToPrimary"],"query": "Y"}}
            ]
        }
    },
    "size": 100,
    "aggs":{
        "langs": {
            "terms": {
                "field": "CustomerID",
                "size": 1000
            }
        }
    }
}

 

answered