0
votes

I am using Elastic search repository as per https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.repositories only to read an existing indexed data.

I have an analysed field let's say fullName, for which I am creating s search method in repository as follows: Person.Java

class Person{
   @Field("ID")
   @Id
   long _id;

   @Field(value = "FULL_NAME", type = FieldType.Text)
   String fullName;
}

Repository is as:

@Repository
public interface PersonDataRepository extends ElasticsearchRepository<Person, Long> {

    //this does't work
    List<Person> findAllByFullNameIn(List<String> fullNames);

    //this works
    List<Person> findAllByFullName(String fullName);

}

Since the field is analysed, PersonDataRepository.findAllByFullNameIn(Stream.of("ABC").collect(Colelctors.toList())) doesn't produce any results, while PersonDataRepository.findAllByFullName("ABC") works well.

I found out that this is due to the analysed String field and If I switch to keyword, it should work.

Anybody knows a way around this using Spring data elasticsearch?

Versions: Springboot - 2.3.1.RELEASE Spring Data Elasticsearch: 4.0.1.RELEASE ElasticSearch - 7.6.2

2

2 Answers

1
votes

This was a bug and was recently fixed. It will be contained in versions 4.0.4 and 4.1.RC1

Edit: Both of these versions are released now

0
votes

Solved it by writing a manual query using @Query annotation.

Passed searchquery using keyword instead of complete name as:

{
   "query":{
      "bool":{
         "must":[
            {
               "bool":{
                  "must":[
                     {
                        "terms":{
                           "FULL_NAME.keyword":[
                              "ABC"
                           ]
                        }
                     }
                  ]
               }
            }
         ]
      }
   },
   "version":true
}