Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues when replicating from couchbase bucket to elasticsearch index?

This issue seems to be related to using the XDCR in couchbase. If I had the following simple objects

1: { "name" : "Mark", "age" : 30}
2: { "name" : "Bill", "age" : "forty"}

and set up an elasticsearch index as such

curl -XPUT 'http://localhost:9200/test/couchbaseDocument/_mapping' -d '
  {
    "couchbaseDocument" : {
      "dynamic_templates": [
      {
        "store_generic": {
          "match": "*",
          "mapping": {
            "store": "yes"
          }
        }
      }
      ]
    }
}'

I can then add the two objects to this index using the REST API

curl -XPUT localhost:9200/test/couchbaseDocument/1 -d '{
  "name" : "Mark",
  "age" : 30
}'

curl -XPUT localhost:9200/test/couchbaseDocument/2 -d '{
  "name" : "Bill",
  "age" : "forty"
}'

They are now both searchable (despite the fact the "age" is long for one and string for the other.

If, however, I stored these two objects in a couchbase bucket (rather than straight to elasticsearch) and set up the XDCR the first object replicates fine but the second fails with the following error

failed to execute bulk item (index) index {[test][couchbaseDocument][2], source[{"doc":{"name":"Bill","age":"forty"},"meta":{"id":"2","rev":"8-00000b9360d0a0bf0000000000000000","expiration":0,"flags":0}}]} org.elasticsearch.index.mapper.MapperParsingException: failed to parse [doc.age]

I can't figure out why it works via the REST API but not when couchbase replicates the same objects.

I followed the answer and used the following mapping to get things to work via XDCR

curl -XPUT 'http://localhost:9200/test/couchbaseDocument/_mapping' -d '
{
    "couchbaseDocument" : {
      "properties" : {
        "doc": {
          "properties" : {
            "name" : {"type" : "string", "store" : "yes"},
            "age" : {"type" : "string", "store" : "yes"}
          }
        }
      }
    }
}'

Now all the objects (despite having different types for the same fields) are replicated and searchable. I don't think there was any need to include the dynamic_templates approach I initially tried. The mapping works.

like image 891
Philip O'Brien Avatar asked Dec 21 '25 13:12

Philip O'Brien


1 Answers

It's something you have to solve on elasticsearch side.

If the same field name can contain both numeric values and string values, you should create a mapping first which says that age is a String. So elasticsearch won't try to auto guess type for this field.

Hope this helps

like image 60
dadoonet Avatar answered Dec 24 '25 10:12

dadoonet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!