Skip to content
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

query criteria is converted twice wrongly for custom @ValueConverter #2338

Closed
puppylpg opened this issue Oct 18, 2022 · 0 comments · Fixed by #2339
Closed

query criteria is converted twice wrongly for custom @ValueConverter #2338

puppylpg opened this issue Oct 18, 2022 · 0 comments · Fixed by #2339
Assignees
Labels
type: bug A general bug

Comments

@puppylpg
Copy link
Contributor

puppylpg commented Oct 18, 2022

Today when using @ValueConverter to convert a field customly, I found that spring-data-elasticsearch will invoke PropertyValueConverter#write twice if query return a Stream or Collection in this method.

For example, using this entity(I renamed it as Sample, and defined prefix as foo_) and custom FooConverter, and create a repository class:

public interface SampleRepository extends ElasticsearchRepository<Sample, String> {

    Stream<Sample> findBySomeField(String someField);

    // this method uses findAllBy to just avoid duplicate with findBy in the last method
    List<Sample> findAllBySomeField(String someField);

    Sample findSampleBySomeField(String someField);
}

If the query parameter is what,
the first method will generate the query as:

TRACE [main] tracer [RequestLogger.java:90] curl -iX POST 'http://localhost:9200/foo/_search?scroll=60000ms&typed_keys=true&max_concurrent_shard_requests=5&search_type=query_then_fetch&batched_reduce_size=512' -d '{"from":0,"size":500,"query":{"bool":{"must":[{"query_string":{"query":"foo_foo_what","fields":["someField^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,"explain":false}'

TRACE [main] tracer [RequestLogger.java:90] curl -iX DELETE 'http://localhost:9200/_search/scroll' -d '{"scroll_id":["FGluY2x1ZGVfY29udGV4dF91dWlkDXF1ZXJ5QW5kRmV0Y2gBFnd1aXZSRV9NU1pTSHZVUUs4RWNzbXcAAAAAAAAC1BZBd2NoaTNUV1RPbWx3RW9kVGxRVW1B"]}'

the prefix foo_ will be added twice so the query string becomes into foo_foo_what.

The second and the third do the same:

TRACE [main] tracer [RequestLogger.java:90] curl -iX POST 'http://localhost:9200/foo/_search?typed_keys=true&max_concurrent_shard_requests=5&search_type=query_then_fetch&batched_reduce_size=512' -d '{"from":0,"size":0,"query":{"bool":{"must":[{"query_string":{"query":"foo_foo_what","fields":["someField^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,"explain":false,"track_total_hits":2147483647}'

also as foo_foo_what.

If prefix is foo- as the post wrote originally, the query is stranger:

TRACE [main] tracer [RequestLogger.java:90] curl -iX POST 'http://localhost:9200/foo/_search?scroll=60000ms&typed_keys=true&max_concurrent_shard_requests=5&search_type=query_then_fetch&batched_reduce_size=512' -d '{"from":0,"size":500,"query":{"bool":{"must":[{"query_string":{"query":"foo\\-foo\\-what","fields":["someField^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,"explain":false}'

the query string becomes foo\\-foo\\-what, not only double foo-, but also add slashes as foo\\-.

I think converting query criterias once should be as expected, rather than twice.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 18, 2022
@puppylpg puppylpg changed the title Stream/Collection query criteria is converted twice wrongly for custom @ValueConverter query criteria is converted twice wrongly for custom @ValueConverter Oct 18, 2022
@sothawo sothawo self-assigned this Oct 19, 2022
@sothawo sothawo added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 19, 2022
sothawo added a commit that referenced this issue Oct 19, 2022
sothawo added a commit that referenced this issue Oct 19, 2022
Original Pull Request #2339
Closes #2338

(cherry picked from commit e67150a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants