YaroslavPodorvanov / golang-struct-to-elastic-mapping

https://github.com/olivere/elastic/issues/694
MIT License
14 stars 3 forks source link

Nested field type #7

Closed YaroslavPodorvanov closed 2 years ago

YaroslavPodorvanov commented 2 years ago
type Alias struct {
    Alias string `json:"alias"`
    Name  string `json:"name"`
}

type Company struct {
    ID    int    `json:"id"`
    Alias string `json:"alias"`
    Name  string `json:"name"`
}

type Vacancy struct {
    ID              int     `json:"id"`
    Title           string  `json:"title"`
    Description     string  `json:"description"`
    Company         Company `json:"company"`
    RequiredSkills  []Alias `json:"required_skills"`
    PreferredSkills []Alias `json:"preferred_skills"`
    DesiredSkills   []Alias `json:"desired_skills"`
}
{
  "mappings": {
    "properties": {
      "id": {
        "type": "integer"
      },
      "title": {
        "type": "text"
      },
      "description": {
        "type": "text"
      },
      "company": {
        "type": "nested",
        "properties": {
          "id": {
            "type": "integer"
          },
          "alias": {
            "type": "text"
          },
          "name": {
            "type": "text"
          }
        }
      },
      "required_skills": {
        "type": "nested",
        "properties": {
          "alias": {
            "type": "text"
          },
          "name": {
            "type": "text"
          }
        }
      },
      "preferred_skills": {
        "type": "nested",
        "properties": {
          "alias": {
            "type": "text"
          },
          "name": {
            "type": "text"
          }
        }
      },
      "desired_skills": {
        "type": "nested",
        "properties": {
          "alias": {
            "type": "text"
          },
          "name": {
            "type": "text"
          }
        }
      }
    }
  }
}