Elastic Search 6.4索引创建

时间:2018-10-09 15:41:22

标签: elasticsearch lucene

我在Windows计算机上运行ES 6.4版本。 ES本身运行良好,但是在创建索引时却给了我错误。我使用的映射文件如下:-

{
  "mappings": {
    "household_customer": {
      "properties": {
        "phoneNumber": {
          "type": "string",
          "index": "analyzed",
          "analyzer": "comma_analyzer"
        },
        "householdId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "householdType": {
          "type": "string",
          "index": "not_analyzed"
        },
        "householdEligible": {
          "type": "string",
          "index": "not_analyzed"
        },
        "householdName": {
          "type": "string",
          "index": "not_analyzed"
        },
        "customerId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "customerType": {
          "type": "string",
          "index": "not_analyzed"
        },
        "name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "postalCode": {
          "type": "string",
          "index": "not_analyzed"
        },
        "houseNumber": {
          "type": "string",
          "index": "not_analyzed"
        },
        "houseNumberAddition": {
          "type": "string",
          "index": "not_analyzed"
        },
        "kvk": {
          "type": "string",
          "index": "not_analyzed"
        },
        "iban": {
          "type": "string",
          "index": "not_analyzed"
        },
        "benefitAssigned": {
          "type": "boolean"
        },
        "benefitName": {
          "type": "string",
          "index": "not_analyzed"
        },
        "benefitStatus": {
          "type": "string",
          "index": "not_analyzed"
        },
        "benefitStatusDate": {
          "type": "string",
          "index": "not_analyzed"
        },
        "hasFixed": {
          "type": "boolean"
        },
        "isFixedEligible": {
          "type": "boolean"
        },
        "hasCable": {
          "type": "boolean"
        },
        "isCableEligible": {
          "type": "boolean"
        },
        "hasInternet": {
          "type": "boolean"
        },
        "isInternetEligible": {
          "type": "boolean"
        },
        "hasDigitalTV": {
          "type": "boolean"
        },
        "isDigitalTVEligible": {
          "type": "boolean"
        },
        "eligible": {
          "type": "string",
          "index": "not_analyzed"
        },
        "householdCustomerKey": {
          "type": "string",
          "index": "not_analyzed"
        },
        "activeInd": {
          "type": "string",
          "index": "not_analyzed"
        },
        "blacklistInd": {
          "type": "boolean"
        },
        "blacklistCriteria": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    },
     "settings": {
    "analysis": {
      "analyzer": {
        "comma_analyzer": {
          "tokenizer": "comma_tokenizer"
        }
      },
      "tokenizer": {
        "comma_tokenizer": {
          "type": "pattern",
          "pattern": ","
        }
      }
    }
}
}
}

使用的命令:-http://localhost:9200/household_customer .....我通过邮递员运行了命令

错误:-

{
    "error": {
        "root_cause": [
            {
                "type": "mapper_parsing_exception",
                "reason": "Root mapping definition has unsupported parameters:  [analysis : {analyzer={comma_analyzer={tokenizer=comma_tokenizer}}, tokenizer={comma_tokenizer={pattern=,, type=pattern}}}]"
            }
        ],
        "type": "mapper_parsing_exception",
        "reason": "Failed to parse mapping [settings]: Root mapping definition has unsupported parameters:  [analysis : {analyzer={comma_analyzer={tokenizer=comma_tokenizer}}, tokenizer={comma_tokenizer={pattern=,, type=pattern}}}]",
        "caused_by": {
            "type": "mapper_parsing_exception",
            "reason": "Root mapping definition has unsupported parameters:  [analysis : {analyzer={comma_analyzer={tokenizer=comma_tokenizer}}, tokenizer={comma_tokenizer={pattern=,, type=pattern}}}]"
        }
    },
    "status": 400
}

类似的索引创建方法在ES2.x中有效,而在ES 6.4中则失败

2 个答案:

答案 0 :(得分:0)

您的settings对象位于mappings内部,但是它应该处于同一级别。像这样尝试:

{
    "mappings": {
        "household_customer": {
            "properties": {
                "phoneNumber": {
                    "type": "string",
                    "index": "analyzed",
                    "analyzer": "comma_analyzer"
                },
                "householdId": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                (i omitted some stuff here...)
                "blacklistCriteria": {
                    "type": "string",
                    "index": "not_analyzed"
                }
            }
        }
    },
    "settings": {
        "analysis": {
            "analyzer": {
                "comma_analyzer": {
                    "tokenizer": "comma_tokenizer"
                }
            },
            "tokenizer": {
                "comma_tokenizer": {
                    "type": "pattern",
                    "pattern": ","
                }
            }
        }
    }
}

如果您使用发布的旧版本在旧的Elasticsearch版本上创建了索引,我坚信它会忽略您的设置。因为在早期版本中,检查的方式较少,因此您基本上可以放置几乎所有JSON对象。甚至可能认为它是另一种类型,在早期版本中是可能的。

答案 1 :(得分:0)

有几件事需要更新。如已经指出的,settings应该与mappings处于同一级别。 string的类型也随着Elasticsearch的更新版本而改变。对于未分析的字符串,请使用keyword,对于已分析的字符串,请使用text

{
  "mappings": {
    "household_customer": {
      "properties": {
        "phoneNumber": {
          "type": "text",
          "analyzer": "comma_analyzer"
        },
        "householdId": {
          "type": "keyword"
        },
        "householdType": {
          "type": "keyword"
        },
        "householdEligible": {
          "type": "keyword"
        },
        "householdName": {
          "type": "keyword"
        },
        "customerId": {
          "type": "keyword"
        },
        "customerType": {
          "type": "keyword"
        },
        "name": {
          "type": "keyword"
        },
        "postalCode": {
          "type": "keyword"
        },
        "houseNumber": {
          "type": "keyword"
        },
        "houseNumberAddition": {
          "type": "keyword"
        },
        "kvk": {
          "type": "keyword"
        },
        "iban": {
          "type": "keyword"
        },
        "benefitAssigned": {
          "type": "boolean"
        },
        "benefitName": {
          "type": "keyword"
        },
        "benefitStatus": {
          "type": "keyword"
        },
        "benefitStatusDate": {
          "type": "keyword"
        },
        "hasFixed": {
          "type": "boolean"
        },
        "isFixedEligible": {
          "type": "boolean"
        },
        "hasCable": {
          "type": "boolean"
        },
        "isCableEligible": {
          "type": "boolean"
        },
        "hasInternet": {
          "type": "boolean"
        },
        "isInternetEligible": {
          "type": "boolean"
        },
        "hasDigitalTV": {
          "type": "boolean"
        },
        "isDigitalTVEligible": {
          "type": "boolean"
        },
        "eligible": {
          "type": "keyword"
        },
        "householdCustomerKey": {
          "type": "keyword"
        },
        "activeInd": {
          "type": "keyword"
        },
        "blacklistInd": {
          "type": "boolean"
        },
        "blacklistCriteria": {
          "type": "keyword"
        }
      }
    }
  },
  "settings": {
    "analysis": {
      "analyzer": {
        "comma_analyzer": {
          "tokenizer": "comma_tokenizer"
        }
      },
      "tokenizer": {
        "comma_tokenizer": {
          "type": "pattern",
          "pattern": ","
        }
      }
    }
  }
}

此外,正如您所看到的错误所指出的那样,您需要在comma_analyzer中定义settings。可能使用模式分析器。像这样:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "comma_analyzer": {
          "tokenizer": "my_tokenizer"
        }
      },
      "tokenizer": {
        "my_tokenizer": {
          "type": "pattern",
          "pattern": ","
        }
      }
    }
  }
}