简体   繁体   中英

Applying analyzers on nested data in elastic search

I have the following json data :

{
"employee_id": "190",
"working_office": "India",
"skillsDetails": {
"CSS": "Beginner",
"Financial Services & Insurance": "Beginner",
"Planning": "Moderate",
"Pig": "Beginner",
"SQL": "Moderate",
"Go": "Beginner",
"iOS": "Beginner",
"Storytelling & Storyboarding": "Beginner",
"Relationship building": "Moderate",
"Facilitation": "Moderate"
}

And I have applied analaysers on all fields like employee_id, working_office. But i am clueless as to how to apply it on nested field - skillsDetails

{
"profiles": {      
  "dynamic" : "true",
  "properties": {
    "employee_id": {
      "type": "integer",
        "analyzer":"standard"
    },
    "working_office": {
      "type": "string",
       "analyzer":"edge_ngram_analyzer"
    },
"skillsDetails":{
//I need to apply analyser here.Also I Dont want to hardcode the fieldNames like java,sql ,etc. I want the analyzer to apply over all     skillsdetails
}
}

Any pointers or help would be really helpful.

It depend on how you have your data structured. From the input it looks like you will have dynamic sets for skill and their levels. As per it you can have mapping as below:

{
"profiles": {      
  "dynamic" : "true",
  "properties": {
    "employee_id": {
      "type": "integer"
    },
    "working_office": {
      "type": "string",
       "analyzer":"edge_ngram_analyzer"
    },
"skillsDetails":{
        "type" : "nested",
        "properties": {
                "name" : {"type": "string", "analyzer": "your-analyzer" },
                "experience"  : {"type": "string", "index" : "not_analyzed" }
        }
    }
}

with this you need to have your input json as

{
"employee_id": "190",
"working_office": "India",
"skillsDetails": [
{"name:"CSS", "experience":"Beginner"},
{"name:"Financial Services & Insurance", "experience":"Beginner"},
{"name:"Planning", "experience":"Moderate"},
{"name:"Pig", "experience":"Beginner"},
{"name:"SQL", "experience":"Moderate"},
{"name:"Go", "experience":"Beginner"},
{"name:"iOS", "experience":"Beginner"},
{"name:"Storytelling & Storyboarding", "experience":"Beginner"},
{"name:"Relationship building", "experience":"Moderate"},
{"name:"Facilitation", "experience":"Moderate"}
]
}

With this approach you can have dynamic set of skills in each document.

If you have fix set of skills as specified in your input data then the mapping could be different.But i think that won't be the general case

Edit: Adding mapping for object type:

If you don't want to change the JSON input then you can have the mapping as type object as follows:

{
    "profiles": {      
      "dynamic" : "true",
      "properties": {
        "employee_id": {
          "type": "integer"
        },
        "working_office": {
          "type": "string",
           "analyzer":"edge_ngram_analyzer"
        },
    "skillsDetails":{
            "type" : "object",
            "dynamic": true
        }
       }
    }
}

But the main disadvantage is that it will create yous skills as the field name and expertise as the value. You will face more complexity while making searches. This will also lead to increase in no. of fields (if you have more no. of skills) thereby increasing the cluster state size.

Finally it's upto you and what you want to implement

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM