Elastic API Extension Steps


(nijo) #1

Hello,

I am trying to learn how to extend the existing APIs like search to add something very specific before the call and after the call. I understand the plugins are the way to go, can I anyone point me to documentation around creating a plugin to extend the basic elastic APIs?

Regards
NV


(Ryan Ernst) #2

Take a look at SearchPlugin, which defines the api for extending search.


(nijo) #3

Thanks Ryan. I have seen people extending BaseRestHandler for developing additional features. When do you use that versus this searchplugin? The searchplugin has several methods for search time behavior? Is it mandatory to implement all methods of this interface?


(Ryan Ernst) #4

You do not have to implement every method in SearchPlugin, only those that you want to add additional or custom behavior for. BaseRestHandler is for adding new rest endpoints. You won't be able to modifying anything about existing endpoints (eg _search).


(nijo) #5

Thanks.. I did try. I think I don't want to modify the search behavior, For example, I want to log every request processed by ES elsewhere in a non standard format. I am reading on the web that getRestHandlerWrapper of ActionPlugin could act as a replacement for RestFilter. I could not find a simple example to start playing with it. Could you please point me to a good sample for this?


(Ryan Ernst) #6

A rest handler wrapper could work for your purpose. Note that only one plugin may have a wrapper. So eg if you are trying to work alongside any security plugin (eg xpack), it won't work. I don't think we have any examplesn of a rest handler wrapper. The api is simple though: just return a unary function which takes a RestHandler, and returns a RestHandler.


(nijo) #7

I did notice that about wrappers, I had to remove xpack to make it work in my environment. Is there any plan to support multiple wrappers in the future. If not it will limit developing new generic plugins, especially when we have xpack installed. Or if there is any other way out?


(Ryan Ernst) #8

Unfortunately there are no immediate plans. It is a fundamental issue with the way wrappers work: doing multiple wrappers means the order of wrapping matters. We could not come up with an api that cleanly and clearly allowed, for example, a security plugin to be the "outermost" wrapping (or innermost, I can't remember which). How multiple plugins wrapping interact with each other would be very confusing (eg they could both be trying to do similar things, so the order would determine which one "wins", and one could silently be overriden).


(system) #9

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