簡體   English   中英

Elasticsearch:在路徑下獲取嵌套對象不是嵌套類型

[英]Elasticsearch:Getting nested object under path is not of nested type

我是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指定為profileviews nested ,因此出現錯誤。 有關如何創建nested objects請參閱文檔 您應該像這樣為每個嵌套對象定義nested type

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

希望這可以幫助!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM