0

I am learning elasticsearch with spring data so can someone help me understand better what elasticsearch query is doing here. I am trying to return back only a set of results based off of a certain value, in this case env. It seems to me that this JPQL query, is not making a difference to only return what I ask for. I have also used an @Query with no difference.

-- here is part of my repository class

public interface MyFormRepo extends ElasticsearchRepository<MyForm, String> {
//??? these function calls are not effecting my return

@Query("{\"bool\": {\"must\": [{\"match\": {\"env\": \"?0\"}}]}}")
Page<MyForm> getAllByEnv(String env, Pageable pageable);

Page<MyForm> findAllByEnv(String env, Pageable pageable);

-- Here is part of my entity class

@Document(indexName = "my_form")
public class MyForm {

@Id
private String id;
@Field(type = Text)
private String schema;
@Field(type = Long)
private long version;
@Field(type = Text)
private String env;
P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
Bandit
  • 31
  • 7
  • what date do you have in your index? what do you expect to return, what do you get? Please show same samples. – P.J.Meisch Jan 28 '22 at 20:10

1 Answers1

0

Here is what I understand. Elasticsearch has this concept called Fuzziness (https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness) so in it's searches which is based on Levenshtein distance (https://en.wikipedia.org/wiki/Levenshtein_distance). Spring data does not allow us to modify this out of the box and is considered Fuzziness.AUTO by default. https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.misc. As for the queries neither of them will do anything different. Both findByAllEnv and getAllBeEnv has a fuziness.AUTO, as for the @Query I found a good reason stated at this site: What is difference between match and bool must match query in Elasticsearch. What I ended up finding is that I must implemented a custom repo for that I have found this example/explaination How to query Elastic with Spring-data-elastic.

Bandit
  • 31
  • 7