您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将稀疏向量添加为Elasticsearch中的字段

将稀疏向量添加为Elasticsearch中的字段

问题在于,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)
其他 2022/1/1 18:18:31 有499人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶