ankane / searchkick

Intelligent search made easy
MIT License
6.52k stars 756 forks source link

complex queries #1682

Open jonsgreen opened 3 months ago

jonsgreen commented 3 months ago

I feel hesitant to submit this issue since I am certain it has been covered before although I am unable to find any results that match. I should also preface that I am currently using version 4.6.3 because of being stuck on an earlier version of Elasticsearch.

We have the need to be able to build some more complex search queries that logically combine ands with ors. We can currently achieve some of what we desire by using the _and and _or in a where filter however we then lose the analyzer combining that we get from the main query.

We could also build up a more complex search by using the body option but again we would lose the analyzer configuration that Searchkick provides automatically for the main query.

Is there currently a way to combine some of the default behavior one gets for the main query into the subqueries with _or and _and with Searchkick? If not, is this a feature that would be desired?

I am trying to keep this simple but can add some examples if that would be helpful.

If this feature request issue is totally out of bounds please close it and/or redirect me elsewhere.

jonsgreen commented 3 months ago

For reference I have also posted this question on stackoverflow with a few more details.

jonsgreen commented 3 months ago

So I figured out a bit of a hack where I used Searchkick's main query building functionality with execute: false and misspellings: true and pulled them out of the body and then merged those together with must/should and passed them back into a final search call using the advanced search body option.

I am curious if there would be some way to abstract out the query building part of Query#prepare to make this a bit easier to do? I also don't know how much the code is currently evolving to support a new query DSL.

Anyhow, this is a great gem and I would be happy to try to contribute something but I suspect that there is a lot of complexity in this part of the code and I would need some guidance.