首页 > 解决方案 > 批量请求中的错误:[arg] 无法从 [long] 类型更改为 [float]

问题描述

我在使用 FOSElastica 捆绑包配置时遇到问题。我使用 JMS 序列化程序,并尝试添加具有字段的对象,这些字段实际上包含一个 json 数组。但是,当我尝试填充其中一些时,它给了我这些错误:

  Error in one or more bulk request actions:                                                                                                 

  index: /table_content/table_content/10 caused mapper [corrected_value_float.args.argument1] cannot be changed from type [long] to [float]  
  index: /table_content/table_content/11 caused mapper [difference_value_float.entry] cannot be changed from type [float] to [long]  

目前,我无法理解他如何推断 json 数组中的参数类型。需要明确的是,我认为 JMS 只是像其他任何对象一样序列化对象并将 {"field" : "value"} 关联为 json,这里数据库中的 "value" 是一个实际的 json 数组,所以弹性索引它和种类“猜测”数组值的类型。

/table_content/table_content/10 的有问题的 json 数组(我猜他不喜欢“argument1”末尾的 100):

{
"args": {
"argument1":[0.0002777777777777778,1.123888888888889,2.2475,3.371111111111111,4.494722222222222,5.618333333333334,6.741944444444444,7.865555555555555,8.988888888888889,10.112499999999999,11.23611111111111,12.359722222222222,13.483333333333333,14.606944444444444,15.730555555555556,16.854166666666668,17.977777777777778,19.10138888888889,20.224999999999998,21.34861111111111,22.47222222222222,23.59583333333333,24.71944444444444,25.842777777777776,26.96638888888889,28.09,29.21361111111111,30.33722222222222,31.460833333333333,32.58444444444444,33.70805555555556,34.83166666666667,35.95527777777778,37.07888888888889,38.2025,39.32611111111112,40.44972222222222,41.57333333333334,42.696666666666665,43.82027777777778,44.943888888888885,46.0675,47.191111111111105,48.31472222222222,49.43833333333333,50.56194444444444,51.68555555555555,52.80916666666666,53.93277777777777,55.05638888888888,56.18,57.30361111111111,58.426944444444445,59.550555555555555,60.674166666666665,61.797777777777775,62.921388888888885,64.045,65.16861111111112,66.29222222222222,67.41583333333334,68.53944444444444,69.66305555555556,70.78666666666666,71.91027777777778,73.03388888888888,74.1575,75.28083333333333,76.40444444444445,77.52805555555555,78.65166666666667,79.77527777777777,80.89888888888889,82.0225,83.14611111111111,84.26972222222223,85.39333333333335,86.51694444444445,87.64055555555557,88.76416666666667,89.88777777777779,91.01138888888889,92.13472222222222,93.25833333333334,94.38194444444444,95.50555555555556,96.62916666666666,97.75277777777778,98.87638888888888,100]
}
}

/table_content/table_content/11 的有问题的 json 数组:

{"args": {
"entry":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
}
}

对于第二个有问题的数组,我什至不明白为什么他认为其中一个数字是浮点数,而它只由 0 组成。

即使我对其余对象使用序列化程序,我如何才能告诉他为 json 数组值赋予什么类型?在弹性捆绑包中,它“猜测”这些数组中的类型是什么?

标签: phpsymfonyelasticsearchelastica

解决方案


所以,一段时间后,我找到了解决问题的方法:动态模板索引模板

实际上,我在 ElasticSearch 无法识别某些类型的字段(如日期或 geo_point)时遇到了麻烦,因此我在模板的帮助下强制将它们用于特定命名的字段。

如果您想要我在 FOSElastica 中的配置示例(文档在此处):

fos_elastica:
    serializer: 
        serializer: jms_serializer
    clients:
        default: 
            host: localhost 
            port: 9200
    index_templates: # https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-templates.html
        base_template: # this is a custom name for the index template
            client: default
            template: "*" # this is where you define which indices will use this template
            types:
                _doc: # this is where you define which types will use this (_doc stands for every type/documents)
                    dynamic_templates: # https://www.elastic.co/guide/en/elasticsearch/reference/6.8/dynamic-templates.html
                        dynamic_date_template: # this is a custom name for the dynamic field template
                            match_pattern: regex
                            match: created|updated|tpq_date|taq_date
                            mapping:
                                type: date
                        dynamic_location_template:
                            match: location
                            mapping:
                                type: geo_point

推荐阅读