gpt4 book ai didi

elasticsearch - 按对象类型字段 Elasticsearch 的大小搜索

转载 作者:行者123 更新时间:2023-11-29 02:44:41 25 4
gpt4 key购买 nike

我有这样的映射:

{
"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"
}
}
}

这是行不通的。报错

nested: ElasticSearchIllegalArgumentException[No field found for [mentions] in mapping with types [post]];

我还尝试用 doc['mentions.id'].value.length == 2 替换脚本部分。也是报错

nested: ArrayIndexOutOfBoundsException[10];

如何查询 mentions 对象大小为 2 的记录?

最佳答案

elasticsearch 指南建议对对象使用 size() 而不是 length。所以试试这个:

{
"filter": {
"script": {
"script": "doc['mentions.id'].values.size() == 2"
}
}
}

祝一切顺利

关于elasticsearch - 按对象类型字段 Elasticsearch 的大小搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17314123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com