Kibana Plugin development: Search strategy vs. custom API route

Hello,

I am starting to develop a Kibana plugin, which is supposed to retrieve data from Elasticsearch and present it to the user in tabular form. I had a look at the "search_examples" plugin, which exposes an aggregation search via a custom API route and uses a strategy for two other features ("MyStrategy" and "FibonacciStrategy").

Is my understanding correct that using a custom search strategy works without implementing an API route?

Which variant should be preferred when starting from scratch?

Thanks!

Hi there, awesome to hear you are working on a custom plugin! I'll try to point you in the right direction:

Is my understanding correct that using a custom search strategy works without implementing an API route?

That's correct, the client-side data.search service will handle making the request to the Kibana server, which will already be aware of any search strategies that have been registered.

That said, you should be able to pass pretty much any raw Elasticsearch search query to the search service, so you only really need a custom search strategy if you are doing something very specific (like wanting to transform provided input to ES DSL, or wanting to hit an ES API other than _search)

Which variant should be preferred when starting from scratch?

My recommendation is to stick with the data.search service without any custom routes or strategies, unless you get to a place where that is no longer technically feasible.

If it becomes clear that something more specific is needed, then I would decide based on whether or not you need this functionality to be shared with other plugins:

  • if this is only an API that's to be used by your plugin, I would lean toward creating an /internal/my-api http route, as custom search strategies will automatically be exposed to any other plugin using the search service.
  • if this is an API you intended to share with other plugins, I recommend doing this via the plugin contracts (or in this case, creating a custom search strategy). In general, we avoid sharing http APIs across plugin boundaries whenever possible.

Your answer clarified a lot of things, thank you!

BTW, after posting my question I also found kibana/search.mdx at main · elastic/kibana · GitHub, which is part of the dev_docs. I didn't find these rendered in any public location. I think publishing these would make a great addition to the docs for plugin development (as the GitHub repo apparently isn't indexed by Google and I stumbled across the docs by chance while reading the Kibana sources).

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.