-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Spring Data Repository not taking into account @Field(name) annotation when generating queries for Object Fields #1752
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
Comments
The problem is that the public class Author {
@Field(value = "FirstName", type = FieldType.Text)
private String firstName;
@Field(value = "LastName", type = FieldType.Text)
private String lastName;
} I will add a description of this behaviour to the documentation. But even with this change, the test will fail, because currently the I will later create a bug issue for this, as this should definitely be possible. |
Not having the But the problem really is the nested query. I have implemented a fix with Your demo application successfully runs with this version, what must be changed is: @Field(type = FieldType.Nested, name = "Authors")
private List<Author> authors; The type must be changed to |
Shouldn't it also pass even if the FieldType is FieldType.Object? I know in the Author example it makes sense to use FieldType.Nested and a nested query for names to maintain the independence of each object vs FieldType.Object where the objects are flatted. https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html But in my example even with a FieldType.Object query where the object arrays are flattened I would expect it to return the same 4 documents since the query is just on the FirstName field which is on all 4 documents. |
I added another fix |
Thanks for making the fixes. Will these fixes also be added to 4.0.9 and 4.1.8 releases or will I need to update to version 4.2? |
I will check this evening if this can be backported |
Alas these changes cannot be easily backported to the 4.1 and 4.0 branches, because we had major rewritings in the |
I am having an issue when trying to do a search with a Spring Data Elasticsearch 4 repository when using a Object Field Type. Below is a simple example that is replicating the issue I am having in my application. With Spring Data Elasticsearch 3 the query generated by the repository would use the
@Field(name)
value but it no longer does with Spring Data Elasticsearch 4.The query that it is generating for the Authors.FirstName field repository method according to the logs is:
Request body: {"from":0,"size":10000,"query":{"bool":{"must":[{"query_string":{"query":"John","fields":["authors.firstName^1.0"],"type":"best_fields","default_operator":"and","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"version":true}
I would have expected the fields query to be:
["Authors.FirstName^1.0"]
based on the
@Field
annotation. That is what Spring Data Elasticsearch 3 would generateIs there something I am missing in my configuration for the query to use the
@Field(name)
value in Spring Data Elasticsearch 4?I have a github test setup that reproduces the problem. I just run a Elasticsearch docker container prior to executing the test.
https://github.com/Mynameisbt/nestedobjectquerytest/blob/master/src/test/java/com/mynameisbt/nestedobjectquerytest/NestedobjectquerytestApplicationTests.java
If I remove the custom names for authors and first name then the documents get returned.
Subclass
Repository
The text was updated successfully, but these errors were encountered: