Reputation: 113
I am using couchbase with elasticsearch transport plugin. My issue is about mapping couchbase document to elasticsearch type. It is possible to mapping it adding to elasticsearch.yml:
couchbase.typeSelector: org.elasticsearch.transport.couchbase.capi.RegexTypeSelector couchbase.typeSelector.documentTypesRegex.type: ^type:.+$
and then document in couchbase with id "type:123" is convert to type "type" in elasticsearch.
I am not content about this solution, because it determines type and format of ID field in couchbase and it causing the solution is not "elegant" and it may be troublesome.
It is possible to mapping document using for example "_class" field? This field appears after inserting a document to couchbase using Java API. I thing it will be much better solution.
Thank you for help.
Upvotes: 1
Views: 231
Reputation: 2481
The document id in Couchbase is immutable, which is why the type selector is based on it. Basing the type on some mutable attribute, such as a field, would allow indexing the same document in Couchbase to multiple documents in Elasticsearch. This would mean a loss of data integrity.
To put it another way, the primary key of a document in Couchbase is the id. The primary key of a document in Elasticseach is the _uid, which is created by combining the type and id as {type}#{id}
. We want them to match, which is why the plugin enforces it the way it does.
On a side note, if your type is based on a prefix of the id, you shouldn't use the RegexTypeSelector
, but rather the DelimiterTypeSelector
. That way you only have to specify the delimiter (':' by default) and it will map all prefixes to a type. Saves you having to define a separate regex for each type.
couchbase.typeSelector: org.elasticsearch.transport.couchbase.capi.DelimiterTypeSelector
couchbase.typeSelector.documentTypeDelimiter: ':'
Upvotes: 2