Last active
January 15, 2021 09:58
-
-
Save punit-naik/c04c8429e5b492c5b467b42cf41fbfd5 to your computer and use it in GitHub Desktop.
Elasticsearch - search for keys inside nested field value, which is a map/json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| curl -X GET https://<username>:<password>@<host-url>/<index(es)>/_search?pretty=true -H 'Content-Type: application/json' -d "{\"query\": {\"match_all\":{}}, \"script_fields\": {\"field_keys_prefied_with_a\": {\"script\": {\"lang\": \"painless\", \"source\": \""" Map m = params._source.<nested/map field name>; return (m == null) ? new HashMap() : m.entrySet().stream().filter(e->e.getKey().startsWith(params.prefix)).collect(Collectors.toMap(e->e.getKey(),e->e.getValue())); \""", \"params\": {\"prefix\": \"a\"}}}}, \"size\": 100}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment