我正在从 elasticsearch 0.90.10 和 NEST 0.12.0 升级到 elasticsearch 1.3.4 和 NEST 1.1.2,并且我正在尝试用函数分数查询替换在 0.90.4 中已弃用的自定义分数查询。
这是我的旧代码:
descriptor.Search<IndexedProduct>(s => s
.Index(index)
.From(((page ?? 1) - 1) * paging)
.Size(paging)
.Fields(f => f.ID, f => f.NumberOfSalesLastTwelveMonths, f => f.Description, f => f.itemIsInStock)
.Query(qsc => qsc
.CustomScore(sc => sc
.Query(q => q
.QueryString(qs => qs
.OnFieldsWithBoost(f => f
.Add(entry => entry.Description, 2.0)
.Add(entry => entry.LongDescription, 1.0)
.Add(entry => entry.ShortFamilyAndNumber, 4.0)
.Add(entry => entry.FamilyAndNumber, 4.0)
.Add(entry => entry.Suppliers, 1.5)
.Add(entry => entry.CleanSupplierReferences, 4.0)
.Add(entry => entry.SupplierReferences, 4.0)
.Add(entry => entry.SupplierBrands, 2.0)
.Add(entry => entry.Categories, 1.5)
.Add(entry => entry.ParameterValues, 1.0)
.Add(entry => entry.KeyWords, 2.0)
.Add(entry => entry.EANReferencesWMS, 4.0)
)
.Query(CleanUpText(EscapeSearchString(searchquery)))
.Operator(Operator.and)
)
)
.Script("_score + ((_score > 0.99 ) ? doc['numberOfSalesLastTwelveMonths'].value : 0) + ((_score > 0.99 ) ? doc['itemIsInStock'].value : 0)")
)
));
这是我的新代码:
descriptor.Search<IndexedProduct>(s => s
.Index(index)
.From(((page ?? 1) - 1) * paging)
.Size(paging)
.Fields(f => f.ID, f => f.NumberOfSalesLastTwelveMonths, f => f.Description, f => f.itemIsInStock)
.Query(qsc => qsc
.FunctionScore(fs => fs
.Query(q => q
.QueryString(qs => qs
.OnFieldsWithBoost(f => f
.Add(entry => entry.Description, 2.0)
.Add(entry => entry.LongDescription, 1.0)
.Add(entry => entry.ShortFamilyAndNumber, 4.0)
.Add(entry => entry.FamilyAndNumber, 4.0)
.Add(entry => entry.Suppliers, 1.5)
.Add(entry => entry.CleanSupplierReferences, 4.0)
.Add(entry => entry.SupplierReferences, 4.0)
.Add(entry => entry.SupplierBrands, 2.0)
.Add(entry => entry.Categories, 1.5)
.Add(entry => entry.ParameterValues, 1.0)
.Add(entry => entry.KeyWords, 2.0)
.Add(entry => entry.EANReferencesWMS, 4.0)
)
.Query(CleanUpText(EscapeSearchString(searchquery)))
.DefaultOperator(Operator.And)
)
)
.ScriptScore(sc => sc
.Script("_score + ((_score > 0.99 ) ? doc['numberOfSalesLastTwelveMonths'].value : 0) + ((_score > 0.99 ) ? doc['itemIsInStock'].value : 0)")
)
)
)
);
新代码在使用 SearchParseException 时失败,这是查询(来自.log文件):
[{
"from": 0,
"size": 10,
"fields": ["iD", "numberOfSalesLastTwelveMonths", "description", "itemIsInStock"],
"query": {
"function_score": {
"query": {
"query_string": {
"query": "*",
"fields": ["description^2", "longDescription^1", "shortFamilyAndNumber^4", "familyAndNumber^4", "suppliers^1.5", "cleanSupplierReferences^4", "supplierReferences^4", "supplierBrands^2", "categories^1.5", "parameterValues^1", "keyWords^2", "eANReferencesWMS^4"],
"default_operator": "and"
}
},
"script_score": {
"script": "_score + ((_score > 0.99 ) ? doc['numberOfSalesLastTwelveMonths'].value : 0) + ((_score > 0.99 ) ? doc['itemIsInStock'].value : 0)"
}
}
}
}]
完整日志条目:
[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@7a87107e] lastShard [true] org.elasticsearch.search.SearchParseException: [sta_products_public_nl_635490239970034081][0]: from[0],size[10]: Parse Failure [Failed to parse source [{"from":0,"size":10,"fields":["iD","numberOfSalesLastTwelveMonths","description","itemIsInStock"],"query":{"function_score":{"query":{"query_string":{"query":"*","fields":["description^2","longDescription^1","shortFamilyAndNumber^4","familyAndNumber^4","suppliers^1.5","cleanSupplierReferences^4","supplierReferences^4","supplierBrands^2","categories^1.5","parameterValues^1","keyWords^2","eANReferencesWMS^4"],"default_operator":"and"}},"script_score":{"script":"_score + ((_score > 0.99 ) ? doc['numberOfSalesLastTwelveMonths'].value : 0) + ((_score > 0.99 ) ? doc['itemIsInStock'].value : 0)"}}}}]] at org.elasticsearch.search.SearchService.parseSource(SearchService.java:660) at org.elasticsearch.search.SearchService.createContext(SearchService.java:516) at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:488) at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:257) at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:206) at org.elasticsearch.search.action.SearchServiceTransportAction$5.call(SearchServiceTransportAction.java:203) at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:517) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: org.elasticsearch.index.query.QueryParsingException: [sta_products_public_nl_635490239970034081] script_score the script could not be loaded at org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionParser.parse(ScriptScoreFunctionParser.java:97) at org.elasticsearch.index.query.functionscore.FunctionScoreQueryParser.parse(FunctionScoreQueryParser.java:128) at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:239) at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:342) at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:268) at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:263) at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33) at org.elasticsearch.search.SearchService.parseSource(SearchService.java:644) ... 9 more Caused by: org.elasticsearch.script.ScriptException: dynamic scripting for [mvel] disabled at org.elasticsearch.script.ScriptService.verifyDynamicScripting(ScriptService.java:374) at org.elasticsearch.script.ScriptService.compile(ScriptService.java:335) at org.elasticsearch.script.ScriptService.search(ScriptService.java:509) at org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionParser.parse(ScriptScoreFunctionParser.java:94) ... 16 more
如果我像这样省略 FunctionScore
,它工作正常:
descriptor.Search<IndexedProduct>(s => s
.Index(index)
.From(((page ?? 1) - 1) * paging)
.Size(paging)
.Fields(f => f.ID, f => f.NumberOfSalesLastTwelveMonths, f => f.Description, f => f.itemIsInStock)
.Query(q => q
.QueryString(qs => qs
.OnFieldsWithBoost(f => f
.Add(entry => entry.Description, 2.0)
.Add(entry => entry.LongDescription, 1.0)
.Add(entry => entry.ShortFamilyAndNumber, 4.0)
.Add(entry => entry.FamilyAndNumber, 4.0)
.Add(entry => entry.Suppliers, 1.5)
.Add(entry => entry.CleanSupplierReferences, 4.0)
.Add(entry => entry.SupplierReferences, 4.0)
.Add(entry => entry.SupplierBrands, 2.0)
.Add(entry => entry.Categories, 1.5)
.Add(entry => entry.ParameterValues, 1.0)
.Add(entry => entry.KeyWords, 2.0)
.Add(entry => entry.EANReferencesWMS, 4.0)
)
.Query(CleanUpText(EscapeSearchString(searchquery)))
.DefaultOperator(Operator.And)
)
)
这是查询(通过Wireshark捕获,我无法获取配置为记录所有查询的日志/slowlog):
{
"index": "sta_products_public_nl",
"type": "indexedproduct"
}
{
"from": 0,
"size": 10,
"fields": ["iD", "numberOfSalesLastTwelveMonths", "description", "itemIsInStock"],
"query": {
"query_string": {
"query": "*",
"fields": ["description^2", "longDescription^1", "shortFamilyAndNumber^4", "familyAndNumber^4", "suppliers^1.5", "cleanSupplierReferences^4", "supplierReferences^4", "supplierBrands^2", "categories^1.5", "parameterValues^1", "keyWords^2", "eANReferencesWMS^4"],
"default_operator": "and"
}
}
}
我做错了什么?
添加
script.disable_dynamic: false
并不总是解决问题,我已经在我的elasticsearch.yml中有了这个,但是我继续收到错误输出:
Caused by: org.elasticsearch.script.ScriptException: dynamic scripting for [mvel] disabled
at org.elasticsearch.script.ScriptService.verifyDynamicScripting(ScriptService.java:374)
at org.elasticsearch.script.ScriptService.compile(ScriptService.java:335)
at org.elasticsearch.script.ScriptService.search(ScriptService.java:509)
at org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionParser.parse(ScriptScoreFunctionParser.java:94)
好的,大提示在这里(应该立即与我点击,说实话:))
Caused: org.elasticsearch.script.ScriptException: dynamic scripting for [mvel] disabled
Elasticsearch曾经默认支持脚本,但是自从人们将elasticsearch公之于众(相当于将一个数据库公之于众)后,他们就被这个问题困扰了。
我们发布了一篇博客文章,详细介绍了如何重新启用脚本:
http://www.elasticsearch.org/blog/scripting/
我是Spring Jpa和Hibernate的新手。我试图使用一个定制函数从Oracle数据库中获取数据。我可以定义一个实体及其相关的服务、实现和存储库。此外,我通过使用< code>registerFunction创建了一个新的定制Oracle方言,如下所示。 所以我有两个问题: 1)在我的Oracle数据库中,函数位于不同的模式下。我需要指定它的模式吗?如果是的话怎么做?还是hibernate
我通过扩展将REST数据与Panache一起用于生成JAX RESTful Web服务。在Spring land中,有一种query builder机制,允许Spring数据存储库根据自定义方法签名的名称和返回类型生成SQL查询。 我试图用Panache来实现同样的事情,但到目前为止没有成功。
问题内容: 我有一个涉及Postgresql数据库的任务。我对SQL不太有经验。 我有一张桌子,上面有每周贸易产品的营业额。 对于每周,提供以下信息:产品,周数,每周营业额(可能是正数,也可能是负数,具体取决于天气是购买还是出售了更多产品)。我已经添加了一个列,每个星期都有期末余额。我在表中的第一周所有产品的期末余额(week_number= 0),而其他所有周均为“ null”。下面提供了一些示
上一页下一页都是第一页的内容
我有一个自定义的文章类型(媒体文章),它使用一些自定义字段,有一个自定义分类法(媒体文章类别)和该分类法中的14个术语。我可以使用CPT归档模板输出所有自定义帖子。 我在侧边栏中还有一个菜单,它列出了用于过滤自定义帖子的术语(我使用了一个自定义WP菜单小部件来创建列表)。 我用一个查询设置了一个自定义分类模板。根据args中放置的分类术语,我能够成功地组合或单独显示帖子。因此,如果我不需要使用过滤
查询分数 查询分数。可供游戏场景使用。查询用户当前互动实例下的成就值。 /** * Tida.queryScore 获取游戏分数后的回调函数数据 * @param {Object} result 结果数据 * @param {number} result.errorCode 为0时成功 其它值失败 * @param {number} result.maxPoint 最大值(比如,最短时间)