0
votes

I am trying to save data to elastic search db. My code is as follows:

Pojo class

@Document(indexName = "testindex", type = "test")
public class TestIndex {
    @Id
    private String id;
    @JsonProperty("Name1")
    private String Name;
    public String getId() {return id;}
    public void setId(String id) {this.id = id; }
    public String getName() {return Name;   }
    public void setName(String name) {this.Name = name; }
}

Repository class is as follows:

public interface TestIndexRepository extends ElasticsearchRepository {

   List<TestIndex> findByName(String Name);

}

Test method is as follows:

 public void test() {       
    Iterable<TestIndex> iterable1 = testIndexRepository.findAll();      Iterator<TestIndex> i = iterable1.iterator();       
    while(i.hasNext()){             
    testIndexRepository.save(i.next());         
    } 
    }

problem : it inserts multiple name attribute in db.

"_index": "testindex",
 "_type": "test",
  "_id": "AVE5MsrMtumI2QfxV3kI",
 "_score": 1,
 "_source": {
  "id": "AVE5MsrMtumI2QfxV3kI",
   "name": "Test Index 222",
   "Name1": "Test Index 222"
  }

Any reason why it is happening?

1

1 Answers

0
votes

I think that Jackson and the type inspection of Spring data get in each others way. It gets one property from inspecting the bean properties and one property from the @JsonProperty annotation.

Maybe you can fix it by simply moving the annotation to the getName() method.