question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE] Dynamic search body

See original GitHub issue

I have another improvement suggestion (if you don’t mind 😉

Currently, to pass a Search Body, 2 solutions are implemented:

  1. 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.

  2. 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&param3=value3'

# Proposal 2
elasticdump --searchBodyModule='@./template/my-search-body-module?day_start=value&day_end=another-value&param3=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:closed
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ferronrsmithcommented, Jul 6, 2022

Ok will look into that now

0reactions
fmartinoucommented, Jul 6, 2022

Thank you very much for for reactivity 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create targets for Dynamic Search Ads - Google Ads Help
Increasing your reach without keywords, targeting for Dynamic Search Ads works by matching people's searches on Google with specific pages on your site....
Read more >
About dynamic search ads - Microsoft Advertising Help Center
Dynamic search ads provide a streamlined, low-touch way to make sure customers searching on the Microsoft Search Network find your products or services....
Read more >
Building a Simple Dynamic Search Bar in React.js
Dynamic searching is the functionality that allows a user to type into a search field to have the results filter and render instantly...
Read more >
Simple dynamic search with Vanilla Javascript (ES6)
In this blog post I will show you how to do a dynamic search with Javascript. With dynamic I mean that the search...
Read more >
Google Adds New Features to Responsive Search Ads
Google is adding new features to RSA ad copy options with dynamic features, and increasing its helpfulness with cross-campaign results and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found