【问题标题】:Applying analyzers on nested data in elastic search在弹性搜索中对嵌套数据应用分析器
【发布时间】:2015-07-02 15:26:45
【问题描述】:

我有以下 json 数据:

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

我已经在所有字段上应用了分析器,例如employee_id、working_office。但我对如何将它应用于嵌套字段一无所知-skillDetails

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

任何指示或帮助都会非常有帮助。

【问题讨论】:

    标签: java search elasticsearch lucene elasticsearch-plugin


    【解决方案1】:

    这取决于您的数据结构。从输入看来,您将拥有技能及其水平的动态集合。根据它,您可以进行如下映射:

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

    有了这个,你需要将你的输入 json 作为

    {
    "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"}
    ]
    }
    

    通过这种方法,您可以在每个文档中拥有一组动态技能。

    如果您在输入数据中指定了一组固定技能,那么映射可能会有所不同。但我认为这不是一般情况

    编辑:为对象类型添加映射:

    如果您不想更改 JSON 输入,则可以将映射作为类型对象,如下所示:

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

    但主要的缺点是它会创造你的技能作为领域名称和专业知识作为价值。在进行搜索时,您将面临更多的复杂性。这也将导致数量增加。领域(如果你有更多的技能),从而增加集群状态的大小。

    最后取决于您和您想要实现的内容

    【讨论】:

    • 不改变json就不能按原样添加映射吗?
    猜你喜欢
    • 2019-09-27
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多