Error in bulk request : [arg] cannot be changed from type [long] to [float]
Asked Answered
I

2

6

I'm having trouble with the FOSElastica bundle config. I use the JMS Serializer, and I try to add objects which have fields which contains literally a json array. But, when I try to populate some of them, it gives me these errors :

  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]  

Currently, I'm having trouble understanding how he deduces what type of argument is in the json array. To be clear, I think JMS just serialize the object like any other and associate {"field" : "value"} as json, and here the "value" in the database is an actual json array, so elastica index it and kind of "guess" a type for the values of the array.

Problematic json array for /table_content/table_content/10 (my guess is he doesn't like the 100 at the end of "argument1") :

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

Problematic json array for /table_content/table_content/11 :

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

For the second problematic array, I don't even understand why he considers one of the numbers a float, when it's only made of 0.

How would I be able to tell him what type to give to the json array values, even though I use a serializer for the rest of the objects ? Where in elastica bundle does it "guess" what type is in these arrays ?

Indifferentism answered 10/5, 2019 at 8:15 Comment(4)
Elasticsearch will create a mapping depending on the first document it indexes if you do not provide one. Try checking the _mapping of your index. You can specify a mapping on your own in order to avoid this.Baro
Oh this would make sense since I can't find anything to specify it myself in FOSElastica code. So my only solution would be creating my own mapping and not rely on the serializer then... I'll see, thanks for the heads upIndifferentism
Since my comment seems to have solved your issue, I'm providing it as an answer so you can mark it as the accepted solution. Glad to help, have funBaro
Well it didn't resolve my problem, I can't really do that with FOSElastica and would have to do the mapping all by hand (and I've got like 50 tables with dozens of fields for each, with some interconnected). But it answered the question about how ElasticSearch create a mapping when there's no type explicitly defined, so thanks for that.Indifferentism
B
5

Elasticsearch will create a mapping depending on the first document it indexes if you do not provide one. Try checking the _mapping of your index. You can specify a mapping on your own in order to avoid this.

Baro answered 13/5, 2019 at 11:34 Comment(0)
I
5

So, after some time I found a solution to my problems : Dynamic templates and Index templates

I actually had trouble with ElasticSearch not recognizing some types of fields (like date or geo_point), so I forced them for specifically named fields with help of templates.

If you want an example of my configuration in 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
Indifferentism answered 1/7, 2019 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.