[FEATURE] Dynamic search body
See original GitHub issueI have another improvement suggestion (if you don’t mind 😉
Currently, to pass a Search Body, 2 solutions are implemented:
-
Passing the JSON encoded string as argument (
--searchBody="{\"query\":{\"term\":{\"username\": \"admin\"}}}"
) Which is great because it allows to pass dynamic values (--searchBody="{\"query\":{\"term\":{\"username\": \"${MY_VAR}\"}}}"
) But it’s very limited to very concise search expressions. -
Passing a path to a JSON file (
--searchBody=@/data/searchbody.json
) Which is better for maintainability. But the search query is static and doesn’t allow to pass dynamic variables.
It would be great to add the ability to get the best of both worlds.
Proposal 1: Search body template
Add the ability to refer a template which will render as the JSON search body. For example, with EJS, we would have templates looking like:
{
"query":{
"range": {
"created": {
"gte": "<%= day_start %>T00:00:00",
"lt": "<%= day_end %>T23:59:59"
}
}
},
"sort": [
{
"id": {
"order": "asc"
}
}
]
}
Proposal 2: Search body function
Here the idea would have to provide a JS module (same as for transform modules
) which will return the search body JSON
For both cases, the CLI must provide a way to set the expected variable values.
If we mimic the transform module
design, we could have new args looking like
# Proposal 1
elasticdump --searchBodyTemplate='@./template/my-search-body-template.ejs?day_start=value&day_end=another-value¶m3=value3'
# Proposal 2
elasticdump --searchBodyModule='@./template/my-search-body-module?day_start=value&day_end=another-value¶m3=value3'
N.B. If you find one of these ideas interesting, I can try to implement it and provide a PR.
N.B. Currently, as a workaround, I’ve implemented the EJS solution in another JS module that I call before calling elasticsearch-dump but it’s not very convenient
Issue Analytics
- State:
- Created a year ago
- Comments:11 (4 by maintainers)
Ok will look into that now
Thank you very much for for reactivity 👍