I have some trouble with inheritence and ElasticsearchRepository. My code (short version) : Entities :
public abstract class father{
@Id
protected String identifier;
// constructors
@Field(type= FieldType.String, index = FieldIndex.not_analyzed)
public String uri;
// getter setter
}
/*
* Stored in elastic search
*/
@Document(indexName = "entity1", type = "entity1")
public abstract class sonA extends father{
// constructors
}
/*
* Stored in elastic search
*/
@Document(indexName = "entity2", type = "entity2")
public abstract class sonB extends father{
// constructors
}
Repository :
public interface DataBnfRepository extends
ElasticsearchRepository<SonA, String> {
public SonA findByUri(String uri);
@Query("{ \"filtered\":{ \"filter\":{\"term\":{\"uri\":\"?0\"}}}}")
public SonA findWithUri(String uri);
}
My trouble : I'm able to put data into elastic search but not to retreive them.
If I do a repository.findall() it works.
If I do a repository.findWithUri(uri) it does not work (null result)
Parse exception for findByUri
I tried to search for exemples : https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/test/java/org/springframework/data/elasticsearch/entities/SampleInheritedEntity.java But there's no repository.
What I have found: If i replace the uri by"foo", it works. So the problem is with https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
So i made a test with
uri = foo:bar => parse exception.
uri = "foo:bar" => parse exception.
uri = foo\:bar => parse exception.
uri = "foo\:bar" => parse exception
Before it was inherited I had no problems with the code.
I just put the URI in an object, repository.save(object) and repository.findWithUri(uri), it give me the object.
Any help/suggestion/comments is greatly appreciated. Please. Thank you so much
curl http://localhost:9200/_cat/indices