【发布时间】:2019-07-09 16:27:31
【问题描述】:
我正试图弄清楚如何解决我在 ES 5.6 索引中遇到的这两个问题。
"mappings": {
"my_test": {
"properties": {
"Employee": {
"type": "nested",
"properties": {
"Name": {
"type": "keyword",
"normalizer": "lowercase_normalizer"
},
"Surname": {
"type": "keyword",
"normalizer": "lowercase_normalizer"
}
}
}
}
}
}
我需要创建两个单独的脚本过滤器:
1 - 过滤员工数组大小为 == 3 的文档
2 - 过滤数组第一个元素为“Name”==“John”的文档
我试图迈出第一步,但无法遍历列表。我总是有空指针异常错误。
{
"bool": {
"must": {
"nested": {
"path": "Employee",
"query": {
"bool": {
"filter": [
{
"script": {
"script" : """
int array_length = 0;
for(int i = 0; i < params._source['Employee'].length; i++)
{
array_length +=1;
}
if(array_length == 3)
{
return true
} else
{
return false
}
"""
}
}
]
}
}
}
}
}
}
【问题讨论】:
标签: elasticsearch elasticsearch-painless