How to intercept search request (in a pluign) without creating separate RestAction

Is it possible to intercept the request (and save the payload in ES) in a
plugin without creating a separate RestAction ?

  1. I want to avoid having to add separate url patterns
    (like https://github.com/jprante/elasticsearch-arrayformat)
  2. I want to return the same response ES would return without the plugin.

What would be the best possible to log search request into elasticsearch ?
I know I can create a nginx proxy that would do that but I wanted to have a
solution built in ES.

I was thinking of a service that would schedule puting the payload in ES
so the plugin wouldn't block the response?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/505701c3-f8a0-4a1b-ae58-d6815567a1dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi @Piotr_Majewski,

Did you end up with some solution? I have a ES API extension plugin to intercept all requests sent to ES. you may try the code below. use ES 5.1.x

public class RestRequestInterceptorAction extends BaseRestHandler {

    private static final Logger logger = Loggers.getLogger(RestRequestInterceptorAction.class);
    
    @Inject
    public RestRequestInterceptorAction(Settings settings, RestController controller) {
        super(settings);
        controller.registerFilter(new RestFilter() {
            @Override
            public void process(RestRequest request, RestChannel channel, NodeClient client, RestFilterChain filterChain)
                    throws Exception {
                
                RestRequest newRequest = new RestRequest(request.params(), request.path()) {
                    @Override
                    public String uri() {
//                        logger.info("add customize uri");
                        return request.uri();
                    }

                    @Override
                    public Method method() {
//                        logger.info("method shall be the same");
                        return request.method();
                    }

                    @Override
                    public Iterable<Entry<String, String>> headers() {
//                        logger.info("add customized header to request");
                        return request.headers();
                    }

                    @Override
                    public String header(String name) {
                        return request.header(name);
                    }

                    @Override
                    public boolean hasContent() {
//                        logger.info("has Contect?:" + request.hasContent());
                        return request.hasContent();
                    }

                    @Override
                    public BytesReference content() {
//                        logger.info("customized content is called");
                        return request.content();
                    }
                };
                filterChain.continueProcessing(newRequest, channel, client);
            }});
    }

}