Nested object inside nested object


#1

Hi All,

I am facing problem with below data format.

PUT personal/user/1
    {
    	"userinfo": {
    		"users": [{
    				"uname": "ram",
    				"age": 25,
    				"address": [{
    					"town": "ct",
    					"city": "ap"
    				}]
    			},
    			{
    				"uname": "ramesh",
    				"age": 28,
    				"address": [{
    					"town": "ctx",
    					"city": "ap"
    				}, {
    					"town": "st",
    					"city": "hyd"
    				}]
    			}
    		]
    	}
    }

Below is the mapping file which I created,

PUT personal
{
	"mappings": {
		"user": {
			"properties": {
				"userinfo": {
					"properties": {
						"users": {
							"type": "nested",
							"properties": {
								"address": {
									"type": "nested",
									"properties": {
										"town": {
											"type": "text",
											"fields": {
												"keyword": {
													"type": "keyword",
													"ignore_above": 256
												}
											}
										},
										"city": {
											"type": "text",
											"fields": {
												"keyword": {
													"type": "keyword",
													"ignore_above": 256
												}
											}
										}
									}
								},
								"uname": {
									"type": "text",
									"fields": {
										"keyword": {
											"type": "keyword",
											"ignore_above": 256
										}
									}
								},
								"age": {
									"type": "long"
								}
							}
						}
					}
				}
			}
		}
	}
}

Now I want the document which contains below validation.
uname = "ramesh" and town = "ctx" and city = "ap", i should get a document
uname = "ramesh" and town = "ct" and city = "ap", i should not get document
uname = "ramesh" and town = "ctx" and city = "hyd", i should not get document.

Could you please suggest me for writing query for this scenario.

Thanks,
GRP


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.