我试图创建一个使用脚本script_score
的function_score
.我有几个文件,其rankings
字段是type="nested"
.该字段的映射是:
"rankings": {
"type": "nested",
"properties": {
"rank1": {
"type": "long"
},
"rank2": {
"type": "float"
},
"subject": {
"type": "text"
}
}
}
Run Code Online (Sandbox Code Playgroud)
示例文档是:
"rankings": [
{
"rank1": 1051,
"rank2": 78.5,
"subject": "s1"
},
{
"rank1": 45,
"rank2": 34.7,
"subject": "s2"
}]
Run Code Online (Sandbox Code Playgroud)
我想要实现的是迭代嵌套的排名对象.实际上,我需要使用ie for循环来查找特定内容subject
并使用它rank1, rank2
来计算某些内容.到目前为止,我使用类似的东西,但它似乎不起作用(抛出编译错误):
"function_score": {
"script_score": {
"script": {
"lang": "painless",
"inline":
"sum = 0;"
"for (item in doc['rankings_cug']) {"
"sum = sum + doc['rankings_cug.rank1'].value;" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试查询我的elasticsearch(版本5.0.0)索引中的字段的.raw版本。该字段的名称为“ region”,其映射如下:
{
"properties": {
"region": {
"type": "text", "analyzer": "custom_analyzer",
"fields": {
"raw": {
"type": "keyword", "index": "not_analyzed"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,我最初使用分析的版本设置了区域映射,第二步,我通过添加字段的原始版本更新了映射。
据我从文档和此处的类似问题了解,我可以查询原始字段以获取其区域与我的查询完全匹配的文档。但是,通过使用以下查询,不会返回任何结果。
{
"match": {
"region.raw": "Northern Ireland"
}
}
Run Code Online (Sandbox Code Playgroud)
相反,通过使用我的字段的分析版本,结果将按预期返回。
{
"match": {
"region": "Northern Ireland"
}
}
Run Code Online (Sandbox Code Playgroud)
因为我需要使用原始字段,所以我有以下问题:
非常感谢您的帮助。