inheritance - spring data elasticsearch inheritence no results on query -
i have trouble inheritence , elasticsearchrepository. 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 put data elastic search not retreive them. if repository.findall()
works. if repository.findwithuri(uri)
not work (null result) parse exception findbyuri
i tried search exemples : https://github.com/spring-projects/spring-data-elasticsearch/blob/master/src/test/java/org/springframework/data/elasticsearch/entities/sampleinheritedentity.java there's no repository.
what have found: if replace uri by"foo", works. problem https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
so made test
uri = foo:bar => parse exception.
uri = "foo:bar" => parse exception.
uri = foo\:bar => parse exception.
uri = "foo\:bar" => parse exception
before inherited had no problems code. put uri in object, repository.save(object)
, repository.findwithuri(uri)
, give me object.
any help/suggestion/comments appreciated. please. thank much
try following method.
findbyfatheruri(uri);
this how works child entities. think it's same extended classes well. spring data's point of view, main class sona databnfrepository , it's id 1 linked repository when use findone
method. have traverse through child class field trying use find object. since, not sure 100%, let me know if works once tried.
Comments
Post a Comment