elasticsearch - ElasticSearch rescorer 插件。如何用原始分数解析内部命中
问题描述
我创建一个对 ES 的查询:
GET my-index/_search
{
"query": {
"nested": {
"inner_hits": {},
"score_mode": "max",
"path": "my_nested_field",
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"my_nested_field.value.token_analyzed": {
"query": "Looking for something like this"
}
}
}
]
}
}
]
}
}
}
},
"rescore": {
"my_plugin_name": {
}
}
}
索引中的文档类似于:
{
"some_field": "some_value",
"some_other_field": "some_other_value",
"my_nested_field": [
{
"value": "some nested value",
"something_else": "something else"
},
{
"value": "some nested value 2",
"something_else": "something else 2"
}
]
]
}
我的自定义 rescorer 插件已执行,一切都很好。我想优化我的插件。目前,当我点击某个文档时,我会使用其中my_nested_field
的每个元素来重新评分顶级文档。我只想使用那些实际导致点击的那些来重新评分顶级文档。但是我不知道如何过滤掉那些没有导致插件命中的。
我当前的代码:
public TopDocs rescore(TopDocs topDocs, IndexSearcher searcher, RescoreContext rescoreContext) throws IOException {
for (int i = 0; i < topDocs.scoreDocs.length; i++) {
Document document = searcher.doc(topDocs.scoreDocs[i].doc);
String json = parserSource(document);
}
...
private String parseSource(Document document) {
return new String(document.getField("_source").binaryValue().bytes, StandardCharsets.UTF_8);
}
我正在寻找的东西不在 path_source
中,但我可以像这样解析的唯一东西是_source
and _id
。我希望这是因为您只能解析存储的字段。但是肯定有某种方法可以解析内部点击得分结果吗?
在每个文档源旁边的实际 ES 响应中都有这个(但我不知道如何在插件中解析这些东西):
"inner_hits": {
"my_nested_field": {
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 4.2184687,
"hits": [ // I NEED THIS STUFF NOT THE _source
{
"_index": "my-index",
"_type": "_doc",
"_id": "8b3d929a-8e90-4ce7-aa1e-7f11ec16de1e",
"_nested": {
"field": "my_nested_field",
"offset": 2
},
"_score": 4.2184687,
"_source": {
"value": "Some value which was actually hit",
}
}
]
}
}
}
旁注:进行查询后,我需要完整的文档,而不仅仅是嵌套字段。
解决方案
推荐阅读
- c - 如何通过将节点传递给另一个函数来分配内存?
- sqoop - 使用 sqoop 从 Mysql 中提取值到 HDFS
- javascript - 如何检查 DOM 节点文本值数组是否等于某个字符串?
- windows - git svn clone 卡在 perl.exe
- php - 带有 Bootstrap 网格的 Wordpress 循环。如何优化这段代码?
- flutter - Flutter 如何计算屏幕宽度
- android - 无法获取资源“https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom”
- c# - 如何实现身份验证和授权 WEBAPI 2 .NET 应用程序?尝试 JWT 库
- javascript - 通过jquery更改html视频播放器css
- python - 根据之前的值循环一个函数?