使用自定义分析器在Elasticsearch上创建索引时出错

时间:2016-12-10 02:08:14

标签: elasticsearch elasticsearch-2.0

我正在尝试使用自定义默认分析器创建索引。 我已经检查了以下问题:

但他们没有解决问题。

这是我的架构:

put /emails
{
   "mappings": {
      "email": {
         "analyzer": "lkw",
         "properties": {
            "createdOn": {
               "type": "date",
               "store": true,
               "format": "strict_date_optional_time||epoch_millis"
            },
            "data": {
               "type": "object",
               "dynamic": "true"
            },
            "from": {
               "type": "string",
               "store": true
            },
            "id": {
               "type": "string",
               "store": true
            },
            "sentOn": {
               "type": "date",
               "store": true,
               "format": "strict_date_optional_time||epoch_millis"
            },
            "sesId": {
               "type": "string",
               "store": true
            },
            "subject": {
               "type": "string",
               "store": true,
               "analyzer": "standard"
            },
            "templates": {
               "properties": {
                  "html": {
                     "type": "string",
                     "store": true
                  },
                  "plainText": {
                     "type": "string",
                     "store": true
                  }
               }
            },
            "to": {
               "type": "string",
               "store": true
            },
            "type": {
               "type": "string",
               "store": true
            }
         }
      },
      "event": {
         "_parent": {
            "type": "email"
         },
         "analyzer": "lkw",
         "properties": {
            "id": {
               "type": "string",
               "store": true
            },
            "origin": {
               "type": "string",
               "store": true
            },
            "time": {
               "type": "date",
               "store": true,
               "format": "strict_date_optional_time||epoch_millis"
            },
            "type": {
               "type": "string",
               "store": true
            },
            "userAgent": {
               "type": "string",
               "store": true
            }
         }
      }
   },
   "settings": {
      "analysis": {
         "analyzer": {
            "lkw": {
               "tokenizer": "keyword",
               "filter": [
                  "lowercase"
               ],
               "type": "custom"
            }
         }
      }
   }
}

当我执行上面的命令时,我收到此错误:

{
       "error": {
          "root_cause": [
             {
                "type": "mapper_parsing_exception",
                "reason": "Root mapping definition has unsupported parameters:  [analyzer : lkw]"
             }
          ],
          "type": "mapper_parsing_exception",
          "reason": "Failed to parse mapping [event]: Root mapping definition has unsupported parameters:  [analyzer : lkw]",
          "caused_by": {
             "type": "mapper_parsing_exception",
             "reason": "Root mapping definition has unsupported parameters:  [analyzer : lkw]"
          }
       },
       "status": 400
    }

1 个答案:

答案 0 :(得分:0)

由于您只有几个字符串字段,我建议您只需在需要的地方指定standard分析器,就像您对PUT /emails { "mappings": { "email": { "properties": { "createdOn": { "type": "date", "store": true, "format": "strict_date_optional_time||epoch_millis" }, "data": { "type": "object", "dynamic": "true" }, "from": { "type": "string", "store": true, "analyzer": "lkw" }, "id": { "type": "string", "store": true, "analyzer": "lkw" }, "sentOn": { "type": "date", "store": true, "format": "strict_date_optional_time||epoch_millis" }, "sesId": { "type": "string", "store": true, "analyzer": "lkw" }, "subject": { "type": "string", "store": true, "analyzer": "standard" }, "templates": { "properties": { "html": { "type": "string", "store": true, "analyzer": "lkw" }, "plainText": { "type": "string", "store": true, "analyzer": "lkw" } } }, "to": { "type": "string", "store": true, "analyzer": "lkw" }, "type": { "type": "string", "store": true, "analyzer": "lkw" } } }, "event": { "_parent": { "type": "email" }, "properties": { "id": { "type": "string", "store": true, "analyzer": "lkw" }, "origin": { "type": "string", "store": true, "analyzer": "lkw" }, "time": { "type": "date", "store": true, "format": "strict_date_optional_time||epoch_millis" }, "type": { "type": "string", "store": true, "analyzer": "lkw" }, "userAgent": { "type": "string", "store": true, "analyzer": "lkw" } } } }, "settings": { "analysis": { "analyzer": { "lkw": { "tokenizer": "keyword", "filter": [ "lowercase" ], "type": "custom" } } } } } 字段所做的那样:

def remove_furigana(content):
    furigana = False
    expression = ""
    for character in content:
        if character == '[':
            furigana = True
        elif character == ']':
            furigana = False
        elif not furigana:
            expression += character
    return expression.replace(" ", "")

def retrieve_article():
    c.execute('SELECT content FROM sentence WHERE article_id = "k10010770581000"')
    for row in c.fetchall():
        print(remove_furigana(row))