appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.89k stars 466 forks source link

How to customize the query before it send to ES #485

Closed shili167 closed 6 years ago

shili167 commented 6 years ago

Hi,

Is there a way to grab the query before it send to Elastic Search server, and change the query? I need to add an "include", "exclude", and change the "highlight" part of the query.

Thank you!

metagrover commented 6 years ago

Hello @shili167, we recently added support for include and exclude fields on the result components. Check docs here.

You can use beforeSend method on ReactiveBase to transform the network request before execution. Refer docs here.

Hope that helps!

shili167 commented 6 years ago

Thank you! I tried include and exclude in result, but the props didn't get inserted into the query (_source) that send to elastic search....maybe it is a new feature, I need to update the version of the library?

Do you have a quick sample for beforeSend function to retrieve the current query?

metagrover commented 6 years ago

Make sure you're on the latest version of reactivesearch. You can do:

<ReactiveBase
    ...props
    beforeSend={(request) => {
        // you will have access to the query inside the request object's body
        // update the request as you like
        // and return the updated request

        return updatedRequest;
    }}
/>