首页 > 解决方案 > 如何在弹性搜索中访问存储的二维浮点数组?

问题描述

index_body = {
    "mappings": {
        "properties": {
            "question": {
                "type": "text"
            },
            "question_vec": {
                "type": "float",
            },
            "q_id": {
                "type": "int"
            }
        }
    }
}

这是我的索引体。在“question_vec”中,我传递了二维数组浮点数组,但在查询数据库时无法访问它,因为我的指标分数取决于它,RequestError(400, 'search_phase_execution_exception', 'runtime error')

这是示例 body_query,实际查询更复杂

s_body = {
    "query": {
        "script_score": {
            "query": {
                "match_all": {}
            },
            "script": {
                "lang":   "painless",
                "source": """
                        int score = 100;
                        int len1 = (params.query_vector[0]).length;
                        int len2 = doc['question_vec'].length;
                        return doc['question_vec'][0][0];
                       """
                
                ,
                "params": {"query_vector": query_vec}
            }
        }
    }
}

标签: python-3.xdatabaseelasticsearchelastic-stackelasticsearch-painless

解决方案


推荐阅读