0

我的映射如下所示:

    "mappings": {
        "nodes": {
            "properties": {
                "createdAt": {
                    "type": "date",
                    "format": "dateOptionalTime"
                },
                "data": {
                    "type": "string"
                },
                "isFile": {
                    "type": "boolean"
                },
                "isPublic": {
                    "type": "boolean"
                },
                "location": {
                    "properties": {
                        "_id": {
                            "type": "string"
                        }
                    }
                },
                "name": {
                    "type": "string"
                },
                "owner": {
                    "properties": {
                        "_id": {
                            "type": "string"
                        },
                        "username": {
                            "type": "string"
                        }
                    }
                },
                "sharedWith": {
                    "type": "object"
                }
            }
        }
    }

当我执行以下查询时:

"filter": {
      "term": {
            "owner.username": "user_69d349"
      }
}

我得到了正确的结果,但是当我这样做时

"filter": {
    "term": {
        "owner._id": "RvdDC"
    }
}

我没有得到任何结果。

我正在使用以下文档:

{
    "_index": "nodess",
    "_type": "nodes",
    "_id": "I7Cac9n",
    "_score": 1.0,
    "_source": {
        "name": "stream",
        "isFile": true,
        "owner": {
            "_id": "RvdDC",
            "username": "user_69349"
        },
        "sharedWith": [],
        "isPublic": false,
        "location": {
            "_id": null
        },
        "data": "baked baked baked hey",
        "createdAt": "2015-03-24T00:53:53.551Z"
    }
}
4

1 回答 1

1

我想这是因为你没有使用nested类型。

是一个很好的解释,当您不使用嵌套类型时会发生什么。基本上,当您索引对象数组时,您的文档会被展平。

你必须告诉 ES 你正在使用嵌套类型。

      "owner": {
            "type": "nested", //<-- declare type here
            "properties": {
                "_id": {
                    "type": "string"
                },
                "username": {
                    "type": "string"
                }
            }
        },
于 2015-03-26T21:08:51.597 回答