Elasticsearch painless 找不到某些字段
Elasticsearch painless cannot find some fields
有类似以下文件:
{
"lastModified": "2022-01-14T09:33:48.232Z",
"uuid": "01234567",
"started": "2022-01-14T09:31:27.651Z",
"editing": false,
"approved": true,
"statistics": {
"teams": {
"team1": {
"name": "Team1",
"score": 0,
"winner": false,
"apiId": "1"
},
"team2": {
"name": "Team2",
"score": 2,
"winner": true,
"apiId": "2"
}
}
}
}
我尝试 select 仅记录其中一个团队具有特定 apiId 的文档。由于 statistics.teams 不是列表而是对象(java 中的映射),我很难实现它。
经过一些常规查询的尝试后,我得到了无痛脚本,但我还是遇到了错误。
有了这个查询
{
"query": {
"bool": {
"must": [
//{"script": { "script": {"source": "!doc['editing'].value"} }}
{"script": {
"script": {
"inline": "def statistics = doc['statistics'].value; return doc['editing'].value == params.isEditing;",
"lang": "painless",
"params": {
"isEditing": 2
}
}
}}
]
}
}
}
我收到以下错误消息。注释掉的工作正常,无痛找到 editing 属性 但不是 statistics
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:65)",
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:27)",
"statistics = doc['statistics'].value; ",
" ^---- HERE"
],
"script": "def statistics = doc['statistics'].value; return doc['editing'].value == params.isEditing;",
"lang": "painless",
"position": {
"offset": 21,
"start": 4,
"end": 42
}
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "matches2",
"node": "7K26XVgxRv6Dz8yDMUrhjg",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:65)",
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:27)",
"statistics = doc['statistics'].value; ",
" ^---- HERE"
],
"script": "def statistics = doc['statistics'].value; return doc['editing'].value == params.isEditing;",
"lang": "painless",
"position": {
"offset": 21,
"start": 4,
"end": 42
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [statistics] in mapping"
}
}
}
]
},
"status": 400
}
Elasticsearch 没有看到根文档的统计参数。
任何人都可以帮我 select 仅在其中一个团队具有特定 apiId 的文档中处理吗?
非常感谢!
您不需要任何脚本即可实现。您可以简单地使用 multi_match
查询来 运行 对多个字段的查询
POST test/_search
{
"query": {
"multi_match": {
"query": "1",
"fields": ["statistics.teams.*.apiId"]
}
}
}
有类似以下文件:
{
"lastModified": "2022-01-14T09:33:48.232Z",
"uuid": "01234567",
"started": "2022-01-14T09:31:27.651Z",
"editing": false,
"approved": true,
"statistics": {
"teams": {
"team1": {
"name": "Team1",
"score": 0,
"winner": false,
"apiId": "1"
},
"team2": {
"name": "Team2",
"score": 2,
"winner": true,
"apiId": "2"
}
}
}
}
我尝试 select 仅记录其中一个团队具有特定 apiId 的文档。由于 statistics.teams 不是列表而是对象(java 中的映射),我很难实现它。
经过一些常规查询的尝试后,我得到了无痛脚本,但我还是遇到了错误。
有了这个查询
{
"query": {
"bool": {
"must": [
//{"script": { "script": {"source": "!doc['editing'].value"} }}
{"script": {
"script": {
"inline": "def statistics = doc['statistics'].value; return doc['editing'].value == params.isEditing;",
"lang": "painless",
"params": {
"isEditing": 2
}
}
}}
]
}
}
}
我收到以下错误消息。注释掉的工作正常,无痛找到 editing 属性 但不是 statistics
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:65)",
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:27)",
"statistics = doc['statistics'].value; ",
" ^---- HERE"
],
"script": "def statistics = doc['statistics'].value; return doc['editing'].value == params.isEditing;",
"lang": "painless",
"position": {
"offset": 21,
"start": 4,
"end": 42
}
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "matches2",
"node": "7K26XVgxRv6Dz8yDMUrhjg",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:65)",
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:27)",
"statistics = doc['statistics'].value; ",
" ^---- HERE"
],
"script": "def statistics = doc['statistics'].value; return doc['editing'].value == params.isEditing;",
"lang": "painless",
"position": {
"offset": 21,
"start": 4,
"end": 42
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [statistics] in mapping"
}
}
}
]
},
"status": 400
}
Elasticsearch 没有看到根文档的统计参数。
任何人都可以帮我 select 仅在其中一个团队具有特定 apiId 的文档中处理吗?
非常感谢!
您不需要任何脚本即可实现。您可以简单地使用 multi_match
查询来 运行 对多个字段的查询
POST test/_search
{
"query": {
"multi_match": {
"query": "1",
"fields": ["statistics.teams.*.apiId"]
}
}
}