python使用elasticsearch设置mapping时报错:
elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'No handler for type [string] declared on field [url]')
mappings = {
"include_type_name ": True,
"properties": {
"id": {
"type": "long"
},
"url": {
"type": "string",
"index": True,
"analyzer": "KeywordAnalyzer"
},
"title": {
"type": "text",
"index": True,
"analyzer": "ik_max_word",
"similarity": "BM25"
},
"text": {
"type": "text",
"index": True,
"analyzer": "ik_max_word",
"similarity": "BM25"
}
}
}
造成这个错误的原因是elasticsearch6.0之后的版本取消了string类型,使用text类型来替代了string。将
"type": "string" 改为 "type": "text"
就可以了。
note:elasticsearch6.0之后的版本不但取消了string了,
"index":"analyzed" 也应该改为boolean型了 "index":True
否则也会跟以上类似的错误。