【发布时间】:2021-10-28 18:16:38
【问题描述】:
我有这样的映射:
{
"post": {
"properties": {
"author_gender": {
"type": "string",
"index": "not_analyzed",
"omit_norms": true,
"index_options": "docs"
},
"author_link": {
"type": "string",
"index": "no"
},
"content": {
"type": "string"
},
"mentions": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"profile_image_url": {
"type": "string"
},
"screen_name": {
"type": "string"
}
}
}
}
}
我需要按mentions 对象的大小进行搜索。我试过这个:
{
"filter": {
"script": {
"script": "doc['mentions'].values.length == 2"
}
}
}
这不起作用。报错
嵌套:ElasticSearchIllegalArgumentException[未找到字段 [提及] 与类型 [post] 的映射];
我也尝试用doc['mentions.id'].value.length == 2 替换脚本部分。也是报错
嵌套:ArrayIndexOutOfBoundsException[10];
如何查询mentions对象大小为2的记录?
【问题讨论】:
-
我猜
mentions是一个数组?在什么情况下,不应该这样定义吗? -
@SrikanthVenugopalan...提及不是一个数组,它是一个对象类型,它是一个对象数组elasticsearch.org/guide/reference/mapping/object-typeelasticsearch.org/guide/reference/mapping/array-type..见
lists字段示例,在数组类型中
标签: elasticsearch