Custom maps for jsonTypes with Elasticsearch plugin

The default map template that comes with the Elasticsearch plugin imports every couchbase doc with a map type of "couchbaseDocument".

According to the ES guide, I can make custom a map:
$ curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '{...}'
... and then add a document to that map:
$ curl -XPUT 'http://localhost:9200/twitter/tweet/docid' -d '{...}'

Is there a way to do something similar with the couchbase connector during the replication process?

Hello,
I am trying to change default "couchbase_template.json" with custom mapping for my index type.
Can any buddy share sample of it.

Thank you,
Girish Baldota

1 Answer

« Back to question.

Hello,

So you just need to import the mapping file before starting the indexing (or let's say the replication from Couchbase to Elasticsearch to be more precise). This is done using the command you have described.

You can also use a template file, for example:

curl -XPUT http://localhost:9200/_template/couchbase -d @plugins/transport-couchbase/couchbase_template.json

As you can see here ( https://github.com/couchbaselabs/elasticsearch-transport-couchbase/blob/... ) the template contains the mapping.

Regards
Tug
@tgrall

Thanks for the reply, Tug.

What I am failing to understand is how to apply a mapping to a particular document type. The ES guide describes 4 ways to actually set a mapping (config/templates/template.json, PUT _template, PUT _mapping or during the index creation), but has no explanation on how to write the mapping itself.

Take for example two documents with the ids Beer::12345 and Cookie::12345. With Couchbase views, I can create separate indices for these two types of documents by putting the following in a the map function:  if (meta.id.substr(0,6) === "Beer::") //emit something...

Similarly, is there a way to apply a mapping in ES to all beer documents and a different mapping to all cookie documents? Or is this something that I should be handling at the time of query as oppose to the time of indexing?

Did you ever get a clear answer to this question?

Ogdenmd, I don't think that I ever figured this one out. I didn't end up using ElasticSearch, and I don't remember much about it at this point. I believe there is an ElasticSearch Google Group where you might be better off getting info on how to edit the default CB template to better suit your needs.

If full text search is not one of your requirements, you should check out N1QL.