java - Google DataStore with objectify - composite queries on HashMap -
i using google app engine rest service backend , google datastore db , objectify accessing datastore. 1 of properties in entity
map<string,string> customattrs; this because don't know before hand parameters can come client. requirement want able index on these parameters in hashmap. looked @ following question:
gae w/ objectify - can query hashmap?
and tried out mentioned in accepted answer , works me, able index based on attributes in customattrs using
filter("customattrs .key1", "value1") based on whatever queryparams passed client in rest api call.
however, problem comes in case of composite queries. don't know understand, if combine sorting or inequality filter filter, have define combination in file called datastore-indexes.xml . 1 of fields in entity creationtime, , when query returns me list of users, want sort creationtime.
so let's 1 keys in map customattrs city. if want filter users city=london, works fine me. however, if try users city=london sorted creationtime, returns exception , not work. works if add following in file datastore-indexes.xml:
<datastore-index kind="user" ancestor="false" source="manual"> <property name="customattrs.city" direction="asc" /> <property name="creationtime" direction="asc" /> </datastore-index> now defeat purpose of using hashmap since here need know fields inside customattrs before hand.
so there way of performing composite queries without having know fields before hand?
edit:
as mentioned in answer sai, there no way perform these type of queries, without adding before-hand , adding in datastrore-indexes.xml.
i thought of approach, facing different issue there.
in approach, instead of defining property as
map<string,string> customattrs; i have defined list of strings
list<string> customattrs; here strings stored of form "key:value". example, list entity might "city:abc","country:xyz","name:123"
in case, need define following in datastore-indexes.xml:
<datastore-index kind="user" ancestor="false" source="manual"> <property name="customattrs" direction="asc" /> <property name="creationtime" direction="asc" /> </datastore-index> which fine me, since hard-coding/pre-defining attributes, be. able filter city=abc using
filter("customattrs","city:abc") with approach can filter 1 of parameters sort results creationtime.
but problem approach able 1 type of custom filter. meaning if want filter city abc , country xyz( works if use map approach), not able it. there way it. query if entity has property list, there way filter entities have strings "str1" , "str2" in list?
this has nothing objectfy, datastore itself. time query searches on multiple properties or has sorting mentioned (search , sort on 2 different properties), datastore expects matching composite index. datastore designed queries results single index performance. said, if allow dynamic properties names not aware ahead of time, there no way perform queries wanting do. if option, application should limit querying/sorting on these dynamic properties not require composite index. otherwise, have explore alternative options such full text search (either appengine's full text search or elastic search) , see if use case.
Comments
Post a Comment