所以我终于设置了 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/
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在MiniTest::Spec和Capybara中使用以下规范:find_field('Email').must_have_css('[autofocus]')检查名为“电子邮件”的字段是否具有autofocus属性。doc说如下:has_css?(path,options={})ChecksifagivenCSSselectorisonthepageorcurrentnode.据我了解,字段“Email”是一个节点,因此调用must_have_css绝对有效!我做错了什么? 最佳答案 通过JonasNicklas得到了答案:No
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
两者都可以defsetup(options={})options.reverse_merge:size=>25,:velocity=>10end和defsetup(options={}){:size=>25,:velocity=>10}.merge(options)end在方法的参数中分配默认值。问题是:哪个更好?您更愿意使用哪一个?在性能、代码可读性或其他方面有什么不同吗?编辑:我无意中添加了bang(!)...并不是要询问nobang方法与bang方法之间的区别 最佳答案 我倾向于使用reverse_merge方法:option
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use