# Elasticsearch7.x have any solutions to replace existing searchAction or override?

**URL:** <https://discuss.elastic.co/t/elasticsearch7-x-have-any-solutions-to-replace-existing-searchaction-or-override/295334>\
**Category:** Elasticsearch\
**Created:** [January 25, 2022, 10:57am UTC](https://discuss.elastic.co/t/elasticsearch7-x-have-any-solutions-to-replace-existing-searchaction-or-override/295334 "2022-01-25T10:57:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Howells](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/howells/32/77342_2.png) [@Howells](https://discuss.elastic.co/u/Howells)\
**Post date:** [January 25, 2022, 10:57am UTC](https://discuss.elastic.co/t/elasticsearch7-x-have-any-solutions-to-replace-existing-searchaction-or-override/295334/1 "2022-01-25T10:57:08Z")

</div>

I want to do some custom function in RestSearchAction.prepareRequest before "request.withContentOrSourceParamParserOrNull(parser -\> parseSearchRequest(searchRequest, request, parser, setSize));" ,  
like verify query statement compliance ,the nesting depth of query statements.

and We can't do this uniformly on the business side.

Elasticsearch source code:

```auto
 @Override
    public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
        SearchRequest searchRequest = new SearchRequest();
        /*
         * We have to pull out the call to `source().size(size)` because
         * _update_by_query and _delete_by_query uses this same parsing
         * path but sets a different variable when it sees the `size`
         * url parameter.
         *
         * Note that we can't use `searchRequest.source()::size` because
         * `searchRequest.source()` is null right now. We don't have to
         * guard against it being null in the IntConsumer because it can't
         * be null later. If that is confusing to you then you are in good
         * company.
         */
        IntConsumer setSize = size -> searchRequest.source().size(size);
        request.withContentOrSourceParamParserOrNull(parser ->
            parseSearchRequest(searchRequest, request, parser, setSize));

        return channel -> {
            RestCancellableNodeClient cancelClient = new RestCancellableNodeClient(client, request.getHttpChannel());
            cancelClient.execute(SearchAction.INSTANCE, searchRequest, new RestStatusToXContentListener<>(channel));
        };
    }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 22, 2022, 10:57am UTC](https://discuss.elastic.co/t/elasticsearch7-x-have-any-solutions-to-replace-existing-searchaction-or-override/295334/2 "2022-02-22T10:57:47Z")

</div>

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