elasticsearch,Couchdb,elasticsearch" /> elasticsearch,Couchdb,elasticsearch" />

Couchdb 如何将所有标量类型(数字/布尔值/字符串等)设置为“类型”;“字符串”;动态映射期间(使用river插件)

Couchdb 如何将所有标量类型(数字/布尔值/字符串等)设置为“类型”;“字符串”;动态映射期间(使用river插件),couchdb,elasticsearch,Couchdb,elasticsearch,这可能是我想做的非常奇怪的事情。我正在运行一条“河流”来动态索引couchdb中的所有数据。 当多个用户将数据输入系统时,有时映射中会出现冲突(MapperParser Error)。例如: userA添加以下数据-{“tweet”:{“fooval”:“1”} --elasticSearch将此tweet.fooval变量创建为Number(将其解释为数字) userB添加以下数据-{“tweet”:{“fooval”:“false”} --elasticSearch尝试将此tweet.fo

这可能是我想做的非常奇怪的事情。我正在运行一条“河流”来动态索引couchdb中的所有数据。
当多个用户将数据输入系统时,有时映射中会出现冲突(
MapperParser Error
)。例如:

  • userA添加以下数据-
    {“tweet”:{“fooval”:“1”}
    --elasticSearch将此
    tweet.fooval
    变量创建为Number(将其解释为数字)
  • userB添加以下数据-
    {“tweet”:{“fooval”:“false”}
    --elasticSearch尝试将此
    tweet.fooval
    变量创建为布尔值(将其解释为布尔值),并因此出现MapperParser错误
我想你看到问题了。此外,我只想在标量类型级别上执行此操作,因为我不希望将数组/对象视为字符串。我希望在创建映射时将所有标量类型视为字符串


我在文档页面或论坛上找不到任何内容,因此Think会在这里询问方向/指针。

首先,默认情况下,elasticsearch不会解析字符串。因此,如果您将以下JSON传递给elasticsearch:
{“tweet”:{“fooval”:“1”}
它将把
tweet.fooval
视为一个字符串。如果elaticsearch正在分析字符串,请确保在中将
numeric\u detection
date\u detection
设置为false

另一方面,如果elasticsearch收到一个值作为JSON编号,如:
{“tweet”:{“fooval”:1}
,则elasticsearch确实会将该字段映射为long或double。您可以使用动态模板覆盖此行为。以下是一个例子:

curl -XPUT localhost:9200/test-idx -d '{
    "settings": {
        "index.number_of_replicas": 0,
        "index.number_of_shards": 1
    },
    "mappings": {
        "doc": {
            "dynamic_templates" : [
                {
                    "template_obj" : {
                        "match" : "*",
                        "match_mapping_type" : "object",
                        "mapping" : {
                            "type" : "object"
                        }
                    }
                },
                {
                    "template_str" : {
                        "match" : "*",
                        "mapping" : {
                            "type" : "string"
                        }
                    }
                }            
            ]
        }
    }
}'
curl -XPUT localhost:9200/test-idx/doc/1 -d '{
    "count": 123,
    "sold": false,
    "date": "2009-11-15T14:12:12",
    "price": 12.3,
    "description": {
        "weight":  42.3,
        "size": {
            "lenght": 30,
            "width": 20,
            "hight": 10
        }
    }
}'
echo
curl "localhost:9200/test-idx/doc/_mapping?pretty=true"

我可以在river插件中使用动态模板技巧吗?一旦我使用动态模板设置映射,河流就无法启动。[2013-01-16 13:35:35818][WARN][river][Starsmore,Jonothon]未能创建river[test][test]org.elasticsearch.common.settings.NoClassSettingsException:未能加载值为[test]的类是的,您应该能够对river使用动态模板。只需先创建索引,或使用以确保应用了动态模板。您收到的错误表明您正在尝试创建类型为
test
的河流。除非您自己编写了一个带有类型测试的river插件,否则您可能为您的river指定了错误的类型。好吧,下面是我正在做的:curl-XDELETE'localhost:9200/_river/tentest/'curl-XDELETE'localhost:9200/tentest/'curl-XPUT localhost:9200/tentest-d'{“映射”:{“test”:{“dynamic_templates”:[{“template_obj”:{“match”:“,“匹配映射类型”:“对象”、“映射”:{“类型”:“对象”}}、{“模板”{“匹配”:“映射”:{“类型”:“字符串”}}}}}}}}{code>curl-XPUT'localhost:9200/_-river/entitest/_-meta'-d'{”类型”:“entitest”、“coub”:{“主机”:“本地主机”、“端口”:5984,“数据库”:“entitest“:null},“index”:{“index”:“testest”,“type”:“testest”,“bulk\u size”:“100”,“bulk\u timeout”:“10ms”}”很抱歉将其拆分为多个注释,但是评论中文字的限制让我这么做,而且它也不能正确地接受评论中的
code
。基本上,我首先删除了我的测试数据库之前的任何索引/河流-在这里我将其命名为“诱惑”,然后,我按照动态模板的技巧指定一个设置,其中除对象外的所有内容都被视为字符串。然后我试着在索引上创建一条河注意,通过创建映射,我已经创建了索引。在创建河流的步骤中,我得到了这个错误。我做错什么了吗?