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



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

 {
"_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"
                                }
                            ]
                        }
                    ]
                }
 }    ]    }    ] 

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

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

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

     {
  "xyz": {
     "mappings": {
  "abc": {
    "properties": {
      "lastModifiedBy": {
        "type": "string"
      },
      "lastModifiedDate": {
        "type": "date",
        "format": "dateOptionalTime"
      },
      "name": {
        "type": "string"
      },
      "profile": {
        "properties": {
          "lastModifiedBy": {
            "type": "string"
          },
          "lastModifiedDate": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "type": {
            "type": "string"
          },
          "views": {
            "properties": {
              "id": {
                "type": "string"
              },
              "isDefault": {
                "type": "boolean"
              },
              "name": {
                "type": "string"
              },
              "properties": {
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "type": {
                    "type": "string"
                  },
                  "value": {
                    "type": "string"
                  }
                }
              },
              "type": {
                "type": "string"
              },
              "viewId": {
                "type": "string"
              },
              "widgets": {
                "properties": {
                  "elementId": {
                    "type": "string"
                  },
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "properties": {
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "type": {
                        "type": "string"
                      },
                      "value": {
                        "type": "string"
                      }
                    }
                  },
                  "type": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

}}请帮忙!

由于未将type指定为profileviewsnested,因此出现错误。关于如何创建nested objects,请参阅文档。对于像这样的每个嵌套对象,您应该将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"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

希望这能有所帮助!!

最新更新