我在Elasticsearch中映射了DynamoDb中的数据。我想返回一个通过嵌套数据查询它的文档。我对最简单的嵌套查询有疑问:
{
"query": {
"nested": {
"path": "doc.dynamodb.newImage.childCalls.M",
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"match": {
"doc.dynamodb.newImage.childCalls.M.caller.S": "+18002427338"
}
},
{
"match": {
"doc.dynamodb.newImage.childCalls.M.callee.S": "+18002427338"
}
}
]
}
}
}
}
}
看起来我错过了必不可少的东西。这是映射:
"childCalls": {
"properties": {
"M": {
"type": "nested",
"properties": {
"callee": {
"properties": {
"S": {
"type": "string",
"index": "not_analyzed"
}
}
},
"caller": {
"properties": {
"S": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
响应不包含任何错误:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": [
]
}
}
是的,索引包含我不想返回的文档。我也尝试了caller.S
路径,但没有帮助。
UPD
似乎嵌套数据应该是{key: value}
对象才能正确索引。因此,我需要一个预处理器管道,将用对象表示的值转换为平面值。
答案 0 :(得分:0)
好的,几天之后,当对象数组由看起来不像{key: string|number|boolean}
的对象组成时,根本不需要嵌套映射。复杂对象不会像docs中描述的那样进行转换,它们看起来像对象数组。以下是映射:
"childCalls": {
"properties": {
"L": {
"properties": {
"M": {
"properties": {
"callee": {
"properties": {
"S": {
"type": "string",
"index": "not_analyzed"
}
}
},
"caller": {
"properties": {
"S": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}
}
和工作查询:
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"match": {
"doc.dynamodb.newImage.childCalls.L.M.caller.S": "+18002427338"
}
},
{
"match": {
"doc.dynamodb.newImage.childCalls.L.M.callee.S": "+18002427338"
}
}
]
}
}
}