Elasticsearch:在路径下获取嵌套对象不是嵌套类型

时间:2015-12-31 20:12:39

标签: java elasticsearch

我是Elastic搜索世界的新手。基本上我试图根据ID检索嵌套对象。这是我文档的JSON表示。

function draggable( event ){ ... }
$('body').on('draggable', '.item', draggable));

我正在尝试根据视图ID获取小部件。这是我的搜索查询。

 {
"_index": "xyz",
"_type": "abc",
"_id": "12",
"_version": 1,
"found": true,
"_source":
{
    "lastModifiedBy": "12",
    "lastModifiedDate": "2015-12-31T19:45:29.493Z",
    "profile":
    [
        {
            "type": "nested",
            "views":
            [

                {
                    "type": "nested",
                    "id": "view1",
                    "name": "view1",
                    "properties":
                    [
                        {
                            "name": "default",
                            "value": false
                        }
                    ],
                    "widgets":
                    [
                        {
                            "type": "nested",
                            "id": "graph",
                            "name": "graph",
                            "elementId": "ui_graph",
                            "properties":
                            [
                                {
                                    "name": "currency",
                                    "value": "YEN"
                                }
                            ]
                        }

                    ]
                }
 }    ]    }    ] 

我不确定这里有什么问题。但是获取“路径[profile.views]下的嵌套对象不是嵌套类型]”。 下面是我的映射结构

"query" : {
"term" : {
  "_id" : "12"
}
 },
"post_filter" : {
"nested" : {
  "query" : {
    "filtered" : {
      "query" : {
        "match_all" : { }
      },
      "filter" : {
        "term" : {
          "profile.views.id" : "view1"
        }
      }
    }
  },
  "path" : "profile.views"
 }
}
}

} }                                                                                                                                                                     请帮忙!

1 个答案:

答案 0 :(得分:3)

您收到错误是因为您没有为typenested指定profileviews。有关如何创建nested objects的信息,请参阅Docs。您应该为每个嵌套对象type定义nested,如此

{
  "xyz": {
    "mappings": {
      "abc": {
        "properties": {
          "lastModifiedBy": {
            "type": "string"
          },
          "lastModifiedDate": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "name": {
            "type": "string"
          },
          "profile": {
            "type": "nested", <--- here, you need this for every nested object
            "properties": {
              "lastModifiedBy": {
                "type": "string"
              },
              "lastModifiedDate": {
                "type": "date",
                "format": "dateOptionalTime"
              },
              "type": {
                "type": "string"
              },
              "views": {
                "type": "nested",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "isDefault": {
                    "type": "boolean"
                  },
                  "name": {
                    "type": "string"
                  },
                  "properties": {
                    "type": "nested",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "type": {
                        "type": "string"
                      },
                      "value": {
                        "type": "string"
                      }
                    }
                  },
                  "type": {
                    "type": "string"
                  },
                  "viewId": {
                    "type": "string"
                  },
                  "widgets": {
                    "type": "nested",
                    "properties": {
                      "elementId": {
                        "type": "string"
                      },
                      "id": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "properties": {
                        "type": "nested",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string"
                          },
                          "value": {
                            "type": "string"
                          }
                        }
                      },
                      "type": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

希望这会有所帮助!!