问题在于,Elasticsearch无法推断正确的类型。它认为字典中的每个键都是一个新字段(embedding.key)。因此,我们需要提供一个指定类型的映射。在我的情况下,在创建索引后使用Python中的elasticsearch库:
import requests
uri='http://localhost:9200/my_index/_mapping'
json_body="""{
"properties": {
"name": {
"type": "keyword"
},
"reference": {
"type": "keyword"
},
"jurisdiction": {
"type": "keyword"
},
"text": {
"type": "text"
},
"embedding": {
"type": "sparse_vector"
}
}
}""")
headers = {
'Content-Type': 'application/json',
}
requests.put(uri, headers=headers, data=json_body)