Matching elasticsearch data indexed by Titan

2019-09-07 21:34发布

问题:

I have indexed titan data in elasticsearch, it worked fine and indexed but when i see the data in elasticsearch using REST API. the column/property name looks different than from Titan.

For example i have indexed age while inserting data to Titan

final PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
mgmt.buildIndex("vertices",Vertex.class).addKey(age).buildMixedIndex(INDEX_NAME);

and if i see same in elasticsearch

{
      "_index" : "titan",
      "_type" : "vertices",
      "_id" : "sg",
      "_score" : 1.0,
      "_source":{"6bp":30}
    }, 

Looking at the data i can understand "6bp" is age. how this conversion is done? How can i decode it.?

My goal is to insert data to Titan index on ElasticSearch. The user query should search on ElasticSearch using ElasticSearch client becuase we need more search functionality that ElasticSearch supports, if data is searched then get the related result using Titan query.

回答1:

The field names are Long encoded. You can reverse encode using this class

com.thinkaurelius.titan.util.encoding.LongEncoding

or, an even better option if you can use it, would be to simply specify the search field names explicitly using the field mapping:

By default, Titan will encode property keys to generate a unique field name for the property key in the mixed index. If one wants to query the mixed index directly in the external index backend can be difficult to deal with and are illegible. For this use case, the field name can be explicitly specified through a parameter.

mgmt = g.getManagementSystem()
name = mgmt.makePropertyKey('bookname').dataType(String.class).make()
mgmt.buildIndex('booksBySummary',Vertex.class).addKey(name,com.thinkaurelius.titan.core.schema.Parameter.of('mapped-name','bookname')).buildMixedIndex("search")
mgmt.commit()

http://s3.thinkaurelius.com/docs/titan/0.5.1/index-parameters.html#_field_mapping