gpt4 book ai didi

python - Elasticsearch - field_value_factor,缺少参数

转载 作者:数据小太阳 更新时间:2023-10-29 03:06:07 26 4
gpt4 key购买 nike

所以我终于设置了 elasticsearch 数据库并将数据导入其中。

有时当我尝试从前端请求数据时,我会收到 500 错误(并非总是如此,只是有时)。

我尝试从 POSTMAN 请求数据(以查看 ES 错误消息)。

我得到了:

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[9m4uVcf3TLmQ9Kr7z_fSpQ][text][0]: QueryPhaseExecutionException[[text][0]: query[filtered(function score (blended(terms: [url_words:test, domain_words:test, title:test, body:test]), functions: [{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@56319fc9]}{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@60b46f02]}]))->cache(_type:page)],from[0],size[25]: Query Failed [Failed to execute main query]]; nested: ElasticsearchException[Missing value for field [lang_en]]; }{[9m4uVcf3TLmQ9Kr7z_fSpQ][text][1]: QueryPhaseExecutionException[[text][1]: query[filtered(function score (blended(terms: [url_words:test, domain_words:test, title:test, body:test]), functions: [{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@3ca7d41e]}{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@63daf999]}]))->cache(_type:page)],from[0],size[25]: Query Failed [Failed to execute main query]]; nested: ElasticsearchException[Missing value for field [lang_en]]; }{[9m4uVcf3TLmQ9Kr7z_fSpQ][text][2]: QueryPhaseExecutionException[[text][2]: query[filtered(function score (blended(terms: [url_words:test, domain_words:test, title:test, body:test]), functions: [{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@27521539]}{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@66dbac2b]}]))->cache(_type:page)],from[0],size[25]: Query Failed [Failed to execute main query]]; nested: ElasticsearchException[Missing value for field [lang_en]]; }{[9m4uVcf3TLmQ9Kr7z_fSpQ][text][3]: QueryPhaseExecutionException[[text][3]: query[filtered(function score (blended(terms: [url_words:test, domain_words:test, title:test, body:test]), functions: [{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@73bb4f5e]}{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@112dcf1c]}]))->cache(_type:page)],from[0],size[25]: Query Failed [Failed to execute main query]]; nested: ElasticsearchException[Missing value for field [lang_en]]; }{[9m4uVcf3TLmQ9Kr7z_fSpQ][text][4]: QueryPhaseExecutionException[[text][4]: query[filtered(function score (blended(terms: [url_words:test, domain_words:test, title:test, body:test]), functions: [{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@b650549]}{filter(*:*), function [org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction@7fbe90f4]}]))->cache(_type:page)],from[0],size[25]: Query Failed [Failed to execute main query]]; nested: ElasticsearchException[Missing value for field [lang_en]]; }]",
"status": 500
}

请求正文如下:

{
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "test",
"minimum_should_match": "-25%",
"type": "cross_fields",
"tie_breaker": 0.5,
"fields": ["title^3", "body", "url_words^2", "domain_words^8"]
}

},
"functions": [{
"field_value_factor": {
"field": "rank",
"factor": 1
}
},{
"field_value_factor": {
"field": "lang_en"
}
}]
}
},
"from": 0,
"size": 25
}

我明白字段 [lang_en] 的缺失值是问题所在。我用 google 结果玩弄了 es,但没有成功。

ES版本:1.5.2

有什么想法吗?

编辑:

我将 "missing": 0 添加到第二个 field_value_factor,但我得到了这个错误:

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[9m4uVcf3TLmQ9Kr7z_fSpQ][text][0]: SearchParseException[[text][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\": {\n \"function_score\": {\n \"query\": {\n \"multi_match\": {\n \"query\": \"test\",\n \"minimum_should_match\": \"-25%\",\n \"type\": \"cross_fields\",\n \"tie_breaker\": 0.5,\n \"fields\": [\"title^3\", \"body\", \"url_words^2\", \"domain_words^8\"]\n }\n\n },\n \"functions\": [{\n \"field_value_factor\": {\n \"field\": \"rank\",\n \"factor\": 1\n }\n },{\n \"field_value_factor\": {\n \"field\": \"lang_en\",\n \"missing\": 0\n }\n }]\n }\n },\n \"from\": 0,\n \"size\": 25\n }\n]]]; nested: QueryParsingException[[text] field_value_factor query does not support [missing]]; }{[9m4uVcf3TLmQ9Kr7z_fSpQ][text][1]: SearchParseException[[text][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\": {\n \"function_score\": {\n \"query\": {\n \"multi_match\": {\n \"query\": \"test\",\n \"minimum_should_match\": \"-25%\",\n \"type\": \"cross_fields\",\n \"tie_breaker\": 0.5,\n \"fields\": [\"title^3\", \"body\", \"url_words^2\", \"domain_words^8\"]\n }\n\n },\n \"functions\": [{\n \"field_value_factor\": {\n \"field\": \"rank\",\n \"factor\": 1\n }\n },{\n \"field_value_factor\": {\n \"field\": \"lang_en\",\n \"missing\": 0\n }\n }]\n }\n },\n \"from\": 0,\n \"size\": 25\n }\n]]]; nested: QueryParsingException[[text] field_value_factor query does not support [missing]]; }{[9m4uVcf3TLmQ9Kr7z_fSpQ][text][2]: SearchParseException[[text][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\": {\n \"function_score\": {\n \"query\": {\n \"multi_match\": {\n \"query\": \"test\",\n \"minimum_should_match\": \"-25%\",\n \"type\": \"cross_fields\",\n \"tie_breaker\": 0.5,\n \"fields\": [\"title^3\", \"body\", \"url_words^2\", \"domain_words^8\"]\n }\n\n },\n \"functions\": [{\n \"field_value_factor\": {\n \"field\": \"rank\",\n \"factor\": 1\n }\n },{\n \"field_value_factor\": {\n \"field\": \"lang_en\",\n \"missing\": 0\n }\n }]\n }\n },\n \"from\": 0,\n \"size\": 25\n }\n]]]; nested: QueryParsingException[[text] field_value_factor query does not support [missing]]; }{[9m4uVcf3TLmQ9Kr7z_fSpQ][text][3]: SearchParseException[[text][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\": {\n \"function_score\": {\n \"query\": {\n \"multi_match\": {\n \"query\": \"test\",\n \"minimum_should_match\": \"-25%\",\n \"type\": \"cross_fields\",\n \"tie_breaker\": 0.5,\n \"fields\": [\"title^3\", \"body\", \"url_words^2\", \"domain_words^8\"]\n }\n\n },\n \"functions\": [{\n \"field_value_factor\": {\n \"field\": \"rank\",\n \"factor\": 1\n }\n },{\n \"field_value_factor\": {\n \"field\": \"lang_en\",\n \"missing\": 0\n }\n }]\n }\n },\n \"from\": 0,\n \"size\": 25\n }\n]]]; nested: QueryParsingException[[text] field_value_factor query does not support [missing]]; }{[9m4uVcf3TLmQ9Kr7z_fSpQ][text][4]: SearchParseException[[text][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\n \"query\": {\n \"function_score\": {\n \"query\": {\n \"multi_match\": {\n \"query\": \"test\",\n \"minimum_should_match\": \"-25%\",\n \"type\": \"cross_fields\",\n \"tie_breaker\": 0.5,\n \"fields\": [\"title^3\", \"body\", \"url_words^2\", \"domain_words^8\"]\n }\n\n },\n \"functions\": [{\n \"field_value_factor\": {\n \"field\": \"rank\",\n \"factor\": 1\n }\n },{\n \"field_value_factor\": {\n \"field\": \"lang_en\",\n \"missing\": 0\n }\n }]\n }\n },\n \"from\": 0,\n \"size\": 25\n }\n]]]; nested: QueryParsingException[[text] field_value_factor query does not support [missing]]; }]",
"status": 400
}

最佳答案

在至少一个文档中,字段 lang_en 为 null、空或根本不存在。

您需要修改您的 field_value_factor 函数以告诉它在这种情况下该怎么做,方法是使用具有任何默认值的 missing 设置(0 , 1, 等等):

{
"field_value_factor": {
"field": "lang_en",
"missing": 1 <---- add this line
}
}

关于python - Elasticsearch - field_value_factor,缺少参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37529203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com