我的文档具有嵌套字段的弹性 这是一个示例文档
"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