填充时出现FOSElasticaBundle NumberFormatException错误

时间:2015-08-11 17:05:17

标签: symfony foselasticabundle

我在Symfony 2项目中使用FOSElasticaBundle。由于今天重新索引导致以下错误:

  

index:/ app / hotel / 1导致MapperParsingException [无法解析   [包含pricefrom]];嵌套:NumberFormatException [对于输入字符串:   “410.00”];

在我的学说orm yml中,priceFrom字段定义如下:

priceFrom:
   type: decimal
   nullable: true
   precision: 7
   scale: 2
   comment: ''
   column: price_from

我的fos_elastica配置看起来像这样(config.yml):

fos_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    app:                
        types:
            hotel:
                mappings:   
                    id: ~
                    active: ~                              
                    priceFrom: { type: integer }               
                persistence:
                    driver: orm
                    model: XXX\XXXBundle\Entity\Hotel
                    provider: ~
                    listener:
                        immediate: ~
                    finder: ~           

我用来重新索引的命令:php app/console fos:elastica:populate

上述设置一直有效。我希望有人可以指出我解决这个问题的好方向。

版本: ruflin / elastica(2.1.0) friendsofsymfony / elastica-bundle(v3.1.5) symfony / symfony(v2.6.11)

PS:我的项目中没有其他实体使用priceFrom字段。

2 个答案:

答案 0 :(得分:0)

在映射中,您将PriceFrom定义为整数,但随后传递十进制

我还没有对它进行测试,但它肯定是主要候选人的罪魁祸首。

答案 1 :(得分:0)

Francesco Abeni的回答是正确的。如果您已经将ES中的某些内容推送为整数(或ES将其定义为整数),那么当您尝试在此处保存十进制数据时,它将生成异常。

我总是在映射中明确指定类型:

 id: {"type" : "integer"}
 shop_id: {"type" : "integer"}
 source: {"type" : "string", "index" : "not_analyzed"}

在那里我看到两种解决问题的方法。

  1. 索引别名和索引合并
  2. 指定映射中的类型;杀死指数;再次填写
  3. 我在dev上使用了第二个变体:)