1

I am new to the Elastic search world.Basically I am trying to retrieve the nested objects based on the ID.This is the JSON representation of my document.

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

                    ]
                }
 }    ]    }    ] 

I am trying to get the widgets based on the view id.This is the my search query.

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

I am not sure what is wrong here.But getting "nested object under path [profile.views] is not of nested type]". Below is my mapping structure

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

} } Please help!

5
  • could you post the mapping? Commented Dec 31, 2015 at 20:15
  • @ChintanShah25 : added the mapping Commented Dec 31, 2015 at 20:30
  • 1
    sorry but could you run curl -XGET 'localhost:9200/your_index/your_type/_mapping' and post the output of that instead of java code? Commented Dec 31, 2015 at 20:39
  • @ChintanShah25 : Sorry.added the structure Commented Dec 31, 2015 at 20:49
  • @ChintanShah25 If I wanted to query the widgets based on view id,the structure should be nested ? Commented Dec 31, 2015 at 23:13

1 Answer 1

6

You are getting the error because you have not specified type as nested for profile and views. Refer to the Docs for how to created nested objects . You should be defining type as nested for every nested object like this

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

Hope this helps!!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer.Can u give me some examples in java , how to create the nested type ?.Not finding anything useful in google.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.