Mal*_*LIN 6 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]
Run Code Online (Sandbox Code Playgroud)
目前,我无法理解他如何推断 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]
}
}
Run Code Online (Sandbox Code Playgroud)
/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]
}
}
Run Code Online (Sandbox Code Playgroud)
对于第二个有问题的数组,我什至不明白为什么他认为其中一个数字是浮点数,而它只由 0 组成。
即使我对其余对象使用序列化器,我如何才能告诉他为 json 数组值提供什么类型?在elastica包中,它“猜测”这些数组中的类型是什么?
所以,过了一段时间我找到了解决我的问题的方法:动态模板和索引模板
实际上,我遇到了 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
Run Code Online (Sandbox Code Playgroud)