0

我有字段“技能”的实体映射

 * @ORM\Column(name="skills", type="array", nullable=true)
 * @Groups({"for_profile_project"})
 */
private $skills = [];

弹性配置(这是我的所有配置postebin

团队:

    indexes:
    profile:
        finder: ~
        types:
            team:
                 mappings:
                     id:
                       type: integer
                     slug:
                       type: string
                   projects:
                        type: "nested"
                        properties:
                             id: ~
                             title:
                                type: string
                             description:
                                type: string
                             skills:
                                expose: true
                 persistence:
                      driver: orm
                      model: Artel\ProfileBundle\Entity\Teams
                      provider: ~
                      listener:
                        immediate: true
                      finder: ~

在数据库中我有这样的

a:5:{i:0;a:2:{s:4:"lang";s:10:"JavaScript";s:7:"percent";d:44.169475214305216;}i:1;a:2:{s:4:"lang";s:3:"CSS";s:7:"percent";d:37.235383527019629;}i:2;a:2:{s:4:"lang";s:3:"PHP";s:7:"percent";d:10.312846145221229;}i:3;a:2:{s:4:"lang";s:4:"HTML";s:7:"percent";d:8.1084777328220206;}i:4;a:2:{s:4:"lang";s:10:"ApacheConf";s:7:"percent";d:0.17381738063190688;}}

当我更新实体时出现错误

Merging dynamic updates triggered a conflict: mapper [projects.skills.percent] of different type, current_type [double], merged_type [long]

我需要哪种类型的现场技能或如何更正弹性配置?我的配置有什么问题?

我删除了弹性和运行命令中的所有索引

app/console fos:elastica:populate --no-reset

现在我有了这个映射

"team": {
"properties": {
  "skills": {
    "type": "string"
  },
  "webSite": {
    "type": "string"
  },
  "createdAt": {
    "format": "strict_date_optional_time||epoch_millis",
    "type": "date"
  },
  "projects": {
    "properties": {
      "cost": {
        "type": "long"
      },
      "authorId": {
        "properties": {
          "firstName": {
            "type": "string"
          },
          "lastName": {
            "type": "string"
          },
          "id": {
            "type": "long"
          },
          "username": {
            "type": "string"
          }
        }
      },
      "skills": {
        "type": "string"
      },
      "status": {
        "type": "string"
      }
    }
  },

现在我用一种技能创建测试项目(a:1:{i:0;s:6:"skills";}) 但只有在我编辑实体团队或运行命令时才会自动上传弹性

app/console fos:elastica:populate --no-reset

当我添加真正的项目时

a:5:{i:0;a:2:{s:4:"lang";s:10:"JavaScript";s:7:"percent";d:44.169475214305216;}i:1;a:2:{s:4:"lang";s:3:"CSS";s:7:"percent";d:37.235383527019629;}i:2;a:2:{s:4:"lang";s:3:"PHP";s:7:"percent";d:10.312846145221229;}i:3;a:2:{s:4:"lang";s:4:"HTML";s:7:"percent";d:8.1084777328220206;}i:4;a:2:{s:4:"lang";s:10:"ApacheConf";s:7:"percent";d:0.17381738063190688;}}

并运行

app/console fos:elastica:populate --no-reset

或者当我为此实体团队添加嵌套实体开发人员时出现错误:

Notice: Array to string conversion

mapper_parsing_exception

failed to parse [projects.skills]

illegal_argument_exception

unknown property [lang]

我尝试像整数一样设置百分比,但仍然有错误

a:5:{i:0;a:2:{s:4:"lang";s:10:"JavaScript";s:7:"percent";d:44;}i:1;a:2:{s:4:"lang";s:3:"CSS";s:7:"percent";d:37;}i:2;a:2:{s:4:"lang";s:3:"PHP";s:7:"percent";d:10;}i:3;a:2:{s:4:"lang";s:4:"HTML";s:7:"percent";d:8;}i:4;a:2:{s:4:"lang";s:10:"ApacheConf";s:7:"percent";d:0;}}

我试试

                                 skills:
                                  expose: true
                                  properties:
                                      lang:
                                          type: string
                                      percent:
                                          type: double

但仍然有

      Notice: Array to string conversion

mapper_parsing_exception

failed to parse [projects.skills]

illegal_argument_exception

unknown property [lang]                       

更新

现在我删除了索引并像这样更改配置:

                                skills:
                                  properties:
                                      lang:
                                          type: string
                                      percent:
                                          type: double

并在弹性

          "skills": {
        "properties": {
          "lang": {
            "type": "string"
          },
          "percent": {
            "type": "double"
          }
        }
      },

当我上传具有以下领域技能的实体时:

a:5:{i:0;a:2:{s:4:"lang";s:10:"JavaScript";s:7:"percent";d:44.169475214305216;}i:1;a:2:{s:4:"lang";s:3:"CSS";s:7:"percent";d:37.235383527019629;}i:2;a:2:{s:4:"lang";s:3:"PHP";s:7:"percent";d:10.312846145221229;}i:3;a:2:{s:4:"lang";s:4:"HTML";s:7:"percent";d:8.1084777328220206;}i:4;a:2:{s:4:"lang";s:10:"ApacheConf";s:7:"percent";d:0.17381738063190688;}}

一切都好,但是当我用字段创建实体时

a:1:{i:0;s:8:"skills23";}

我有错误

更新

                             skills:
                               expose: true
                             github:
                                  properties:
                                      lang:
                                          type: string
                                      percent:
                                          type: double

为什么字段 github 不在弹性中创建我不明白(这是我的所有配置postebin

4

1 回答 1

1

"skills": { "type": "string" },

在您的映射中定义为字符串,但在您的数据中,技能是一个带有键 lang 和 percent 的数组,因此您的技能部分映射应该是。

"skills": {
    "properties" : {
        "lang" : {
            "type" : "string"
        },
        "percent" : {
            "type" : "double"
        },
    }
},

编辑:它应该工作。

indexes:
profile:
    finder: ~
    types:
        team:
             mappings:
                 id:
                   type: integer
                 slug:
                   type: string
               projects:
                    type: "nested"
                    properties:
                         id: ~
                         title:
                            type: string
                         description:
                            type: string
                         skills:
                            properties:
                              lang:
                                type: string
                              percent:
                                type: double
             persistence:
                  driver: orm
                  model: Artel\ProfileBundle\Entity\Teams
                  provider: ~
                  listener:
                    immediate: true
                  finder: ~
于 2016-01-19T13:10:55.600 回答