Search code examples
phpsymfonyfoselasticabundle

Symfony Elastic mapping


I have mapping for entity for field "skills"

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

elastic config (this is my all config postebin)

teams:

    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: ~

and in DB I have like this

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;}}

and when I update entity I have error

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

what type of I need for field skills or how to correct elastic config? what's wrong with my config?

I deleted all inde in my elastic and run command

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

and now I have this mapping

"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"
      }
    }
  },

and now I create test project with one skill(a:1:{i:0;s:6:"skills";}) but automatic not upload in elastic only when I edit entity team or run command

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

and when I add real project with

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;}}

and run

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

or when I add for this entity team nested entity developer I have error:

Notice: Array to string conversion

mapper_parsing_exception

failed to parse [projects.skills]

illegal_argument_exception

unknown property [lang]

I try set percent like integer but still have error

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;}}

I try

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

but still have

      Notice: Array to string conversion

mapper_parsing_exception

failed to parse [projects.skills]

illegal_argument_exception

unknown property [lang]                       

UPDATE

Now I deleted index and change config like this:

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

and in elastic

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

and when I upload entity with field skills like this :

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;}}

everything ok but when I create entity with field

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

I have error

UPDATE

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

Why field github not create in elastic I not understand (this is my all config postebin)


Solution

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

    defined as string in your mapping, but in your data skills is an array with keys lang and percent so your partial mapping for skills should be.

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

    Edited : It should work.

    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: ~