elasticsearch - 在elasticsearch中按嵌套字段的大小获取文档?
问题描述
我有带有嵌套字段的弹性文档这是一个示例文档
"Not nestedKey": "Some value"
"sentencesSentiments": [
{
"sentence": "Good",
"sentenceKeyword": "Good",
"score": 0.8,
"magnitude": 0.8
}
]
"Another not nested key" :"Another value"
如您所见,sentencesSentiments是嵌套键,这里是它的映射
"sentencesSentiments": {
"type": "nested",
"properties": {
"magnitude": {
"type": "double",
"store": true
},
"score": {
"type": "double",
"store": true
},
"sentence": {
"type": "text",
"store": true
},
"sentenceKeyword": {
"type": "keyword",
"store": true
}
}
}
现在我需要获取那些“sentencesSentiments”为空的文档以及其他一些布尔过滤器。我尝试了不同的查询,但没有一个有效,这里有一些查询
GET indexName/_search
{
"query": {
"nested": {
"path": "sentencesSentiments",
"query": {
"bool": {
"must": [
{
"exists": {
"field": "sentencesSentiments.sentenceKeyword"
}
}
]
}
}
}
}
}
GET indexName/_search
{
"query": {
"bool": {
"filter": {
"nested": {
"path": "sentencesSentiments",
"filter": {
"script": {
"script" : {
"inline": "doc['sentencesSentiments'].values.length > 0",
"lang": "painless"
}
}
}
}
}
}
}
}
GET indexname/_search
{
"query": {
"bool" : {
"must" : {
"script" : {
"script" : {
"inline": "doc['sentencesSentiments'].values.length > 0",
"lang": "painless"
}
}
}
}
}
}
我也尝试过“values.size()”。无法弄清楚这个的确切语法。 注意:我使用的是弹性版本 5.5
解决方案
推荐阅读
- node.js - 如何使用猫鼬按名称查找元素
- pandas - 大熊猫每小时平均 7 天
- javascript - 将给定数组中重复出现的元素和唯一元素分离为两个包含唯一元素和重复元素的新数组
- python - 如何检查python中的字典列表中是否存在值
- linux - 如何在汇编语言的新行上打印多个字符串
- google-maps - NoSuchMethodError:在 null 上调用了方法“toJson”。- 在 Flutter 中使用 Google 地图和 Firestore
- javascript - 无法访问我的本地服务器,标题有问题吗?
- c++ - 虚拟决赛作为安全
- javascript - 如何使用 Vue API 将样式对象转换为编译后的属性值?
- python - Python Selenium Automation 未从 Node 启动