-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deep copy for QueryBuilder/SearchRequest #869
Comments
@Hronom Thanks for opening this issue. To better understand your use case, have you looked at below ctor for OpenSearch/server/src/main/java/org/opensearch/action/search/SearchRequest.java Lines 123 to 130 in 6252370
|
Hello @Bukhtawar yep checked it, but if you go inside you will see that it not create deep copy, it creates soft copy:
|
May I work on it? |
No need to ask for permission, make PRs. |
@dblock @Bukhtawar |
I am working on this |
@Hronom Is this still an ask to get a deep copy of SearchRequest? If yes, I can start working on it and create a PR. |
Hi @Hronom, following up on this again to check if this is still an ask. If not, I will be closing it. |
@Vishalks still an ask, sometime you have common parts and common code that fill this parts in search request and later on you need to copy what was already input there to use in multi search request, so this is where deep copy needed. Given complexity of how DTO objects organized it's nice to have such feature. |
Thanks for the reply @Hronom. I will start working on this soon. |
I am looking for an issue for my first contribution . Can you help me here. Can I take on this . |
@techrajdeep Sure. Feel free to take this up and put up a PR for this change. Assigning it to you. |
@techrajdeep Did you get a chance to start working on this? Since this is a long pending ask, we would like to get this done soon :) |
@techrajdeep Following up on this one more time. Feel free to put in any queries if you have. |
@Hronom for the use case you are describing, the copy ctor mentioned above could work. The only thing that makes it a shallow copy is that it's not making a true copy of the 'indices' array, but do you really need a copy of it? |
@austintlee yes we need it. To be more specific, imagine situation:
Now, you wanna do a multi-search query, so you start create query using java builders. Shallow copy not helps here, as they point to the same array, as same if you want to adjust objects inside it. Solr, competitor of OpenSearch and Elasticsearch, has this functionality:
However, when you try to migrate from Solr to OpenSearch or Elasticsearch you don't have such possibility. Given the complexity of how serialization/deserialization organized in OpenSearch and Elasticsearch in client library it brings a major blocker as it hard to add. Serialization/deserialization in OpenSearch and Elasticsearch java client not based on popular library like Jackson with simple DTO objects. For some reason Java Client has complex structure. I think it was historically done like that. It brings also complexity for extensibility, when you add plugin that provides custom response/request possibilities. Great example is LTR plugin, I believe OpenSearch and Elasticsearch should revisit this and create modern simple and extensible java client, maybe it will require to create new HTTP, REST API that is friendly to JSON format as same as friendly to serialziation/deserialization libraries, as same as based on simple POJO DTO. |
In that case, the change you want should be in the client side: That will match your Solr example. And to get a deep copy, you can serialize a SearchRequest and deserialize it into a new object (or you can put that routine into a utility method). I hear you on the ser/de argument. But if you want something quick, I suggest you go with the above approach and maybe raise a separate META feature request or an RFC to propose the client overhaul that you are talking about. |
@austintlee you got it right:
But unfortunately, you also need to make sure that all other classes who involved in query building has same support for deep copy. So when you call this method on QueryBuilder/SearchRequest it will go trough child objects and do copy for them accordingly.
That was first attempt to fix this, but... as I mention, the way how code organized for java client - it's not friendly for serializers/deserializers (for example I remember there was also recursion), so this approach fail.
Unfortunately, I don't have time for this now. Not sure even about META feature request too... |
It is very inconvenient when you want to query only by changing the from value. Are you still not considering adding this? |
As a workaround I can propose to serialize and deserialize a |
Hi folks, I sent out a PR to address this by serializing and deserializing a Also, we can implement these logic in a ctor, however the current ctor is already taken to do shallow copying. Not sure what performance impact it would introduce to change the ctor to do deep copy instead. Let me know what you would suggest! |
Here are some cases we actually need a deep copy of a SearchRequest, but we handled them in not-so-elegant ways because lacking of this method:
|
Is your feature request related to a problem? Please describe.
We use multi query and during building multi query using Java API we need have a possibility to get deep copy of
QueryBuilder
/SearchRequest
to re-use common parts that we create for each query.Describe the solution you'd like
Have something like Solr have
SolrQuery.getCopy()
https://github.com/apache/solr/blob/main/solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java#L1178The text was updated successfully, but these errors were encountered: