批量请求中出现错误:[arg]无法从[long]类型更改为[float]

时间:2019-05-10 08:15:06

标签: php symfony elasticsearch elastica

我在使用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数组,因此elastica对其进行了索引并确定了其种类“猜测”数组值的类型。

/ 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数组值指定什么类型呢?它会在弹性束中的哪个位置“猜测”这些阵列中的什么类型?

2 个答案:

答案 0 :(得分:2)

因此,一段时间后,我找到了解决问题的方法:Dynamic templatesIndex templates

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

如果要获取我在FOSElastica(doc is here)中的配置示例:

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

答案 1 :(得分:0)

Elasticsearch将根据它索引的第一个文档(如果您不提供)创建一个映射。尝试检查索引的_mapping。您可以自己指定一个映射,以避免这种情况。