CouchDB River Plugin Indices


I've read the forum to solve my problem, but unfortunately I couldn't handle it or I can't see it from where I am now.

So I have a CouchDB database with multiple types of documents("doc.type"), for which I want to create my_field ElasticSearch River indices, containing complex queries. This field is not (phisically stored) in my documents, but I want it to return 0 when doc.fieldName =="" or to return int(substr(doc.fieldName, 5))) when doc.fieldName != "" , and then query after my_fields.

My questions are:

  1. How can I make this happen?
  2. Should I use ElasticSearch mapping / scripts, CouchDB filters or...(other solution that you can think)?

Please provide an example if possible, so I can fully understand how to implement the answer in my project.

Thanks in advance,

Bogdan Godociu