从couchbase bucket复制到弹性搜索索引的问题? [英] Issues when replicating from couchbase bucket to elasticsearch index?

查看:174
本文介绍了从couchbase bucket复制到弹性搜索索引的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎与在couchbase中使用XDCR有关。如果我有以下简单的对象

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"
          }
        }
      }
      ]
    }
}'

然后我可以使用REST API将这两个对象添加到此索引中。

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"
}'

他们现在都是可以搜索的(尽管事实上,age是一个 long ,而 string 另一个。

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

但是,如果我将这两个对象存储在一个couchbase bucket中(而不是直接到弹性搜索),并且设置XDCR,则第一个对象复制罚款但第二次失败,出现以下错误

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


无法执行批量项(index)index {[test] [couchbaseDocument] [2] ,来源[{doc:{name:Bill,age:40),meta:{id:2,rev:8-00000b9360d0a0bf0000000000000000过期:0,flags:0}}]}
org.elasticsearch.index.mapper.MapperParsingException:无法解析[doc.age]

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]

我无法弄清楚为什么它通过REST API工作,但是当couchbase复制相同的对象时却不行。

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

我按照答案,并使用以下映射通过XDCR使工作起作用

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"}
          }
        }
      }
    }
}'

现在所有对象(尽管有相同字段的不同类型)被复制和搜索。我不认为有必要包括我最初尝试的 dynamic_templates 方法。

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.

推荐答案

这是您必须在弹性搜索方面解决的问题。

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

如果相同的字段名称可以同时包含数值和字符串值,则应首先创建一个映射,说明 age 是一个String。
所以弹性搜索将不会尝试为此字段自动猜测类型。

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.

希望这有助于

这篇关于从couchbase bucket复制到弹性搜索索引的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆