我正在嘗試使用 Python 在 Elasticsearch 中創建我的第一個索引。嘗試創建索引時,我不斷收到以下型別的錯誤:“[text] 型別的映射器 [機構] 上的未知引數 [分析器]”或“映射器中未配置索引”。我嘗試了幾種使用“put_settings”和“put_mappings”方法創建索引的方法,但沒有任何效果。我在 Docker 上使用 Python API 版本 7 和 Elasticsearch 7.12.0。這是我的代碼。
def create_expert_index(index_name="expert_query"):
es = connect()
if es.indices.exists(index=index_name):
es.indices.delete(index=index_name, ignore=[400, 404])
mappings = {
"settings": {
"analysis": {
"analyser": {
"standard_asciifolding": {
"type": "custom",
"tokenizer": "standard",
"filter": ["asciifolding", "lowercase"]
}
}
}
},
"mappings": {
"properties":
{
"first_name":
{
"type": "text",
"analyser": "standard_asciifolding"
},
"last_name":
{
"type": "text",
"analyser": "standard_asciifolding"
},
"email":
{
"type": "text",
"analyser": "standard_asciifolding"
},
"specializations":
{
"type": "text",
"analyser": "standard_asciifolding"
},
"institution":
{
"type": "text",
"analyser": "standard_asciifolding"
}
}
}
}
es.indices.create(index_name, body=mappings)
嘗試使用 create、put_settings 和 put_mappings 方法創建索引。我希望創建索引。
uj5u.com熱心網友回復:
你拼錯了“analyzer”——你用“s”寫了——“analyzer”。請求的其余部分看起來沒問題。考慮將 Kibana 添加到您的實作中,并使用開發工具測驗您的請求。這是糾正這些錯誤的一種非常簡單的方法。這就是我發現這個拼寫錯誤的原因。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/530373.html
標籤:Python弹性搜索索引
