# ES 1.7.6 Search within root and nested objects

**URL:** <https://discuss.elastic.co/t/es-1-7-6-search-within-root-and-nested-objects/277333>\
**Category:** Elasticsearch\
**Created:** [June 29, 2021, 10:46am UTC](https://discuss.elastic.co/t/es-1-7-6-search-within-root-and-nested-objects/277333 "2021-06-29T10:46:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ValeryL](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@ValeryL](https://discuss.elastic.co/u/ValeryL)\
**Post date:** [June 29, 2021, 10:46am UTC](https://discuss.elastic.co/t/es-1-7-6-search-within-root-and-nested-objects/277333/1 "2021-06-29T10:46:15Z")

</div>

Hi there, I'm trying to understand, why search within root and nested objects works in ES 1.7 and now it dosn't work in ES 7.13. May be I'm missing something? I use the following index mapping and search requests:

ES 1.7 index mapping

```auto
{
	"test_index": {
		"aliases": {},
		"mappings": {
			"doc": {
				"properties": {
					"nested_field": {
						"properties": {
							"nested_field_one": {
								"type": "string"
							}
						}
					},
					"root_field_one": {
						"type": "string"
					}
				}
			},
			"objects": {
				"properties": {
					"nested_field": {
						"type": "nested",
						"properties": {
							"nested_field_one": {
								"type": "string",
								"fields": {
									"raw": {
										"type": "string"
									}
								}
							}
						}
					},
					"root_field_one": {
						"type": "string",
						"fields": {
							"raw": {
								"type": "string"
							}
						}
					}
				}
			}
		},
		"settings": {
			"index": {
				"creation_date": "1624954705360",
				"number_of_shards": "5",
				"number_of_replicas": "1",
				"version": {
					"created": "1070699"
				},
				"uuid": "HcpzYGoJTbas9j3-PVWdsA"
			}
		},
		"warmers": {}
	}
}

```

Search request:  
POST test\_index/\_search

```auto
{
	"query": {
		"query_string": {
			"query": "root AND nested"
		}
	},
	"size": 10,
	"from": 0,
	"sort": []
}

```

Response:

```auto
{
	"took": 1,
	"timed_out": false,
	"_shards": {
		"total": 5,
		"successful": 5,
		"failed": 0
	},
	"hits": {
		"total": 1,
		"max_score": 0.16273327,
		"hits": [
			{
				"_index": "test_index",
				"_type": "doc",
				"_id": "1",
				"_score": 0.16273327,
				"_source": {
					"nested_field": [
						{
							"nested_field_one": "nested field text"
						}
					],
					"root_field_one": "root field text"
				}
			}
		]
	}
}

```

ES 7.13 index mapping

```auto
{
	"test_index": {
		"aliases": {},
		"mappings": {
			"properties": {
				"nested_field": {
					"type": "nested",
					"properties": {
						"nested_field_one": {
							"type": "text",
							"fields": {
								"raw": {
									"type": "text"
								}
							}
						}
					}
				},
				"root_field_one": {
					"type": "text",
					"fields": {
						"raw": {
							"type": "text"
						}
					}
				}
			}
		},
		"settings": {
			"index": {
				"routing": {
					"allocation": {
						"include": {
							"_tier_preference": "data_content"
						}
					}
				},
				"number_of_shards": "1",
				"provided_name": "test_index",
				"creation_date": "1624956038877",
				"number_of_replicas": "1",
				"uuid": "IEP4vqxtT06QvuXBWxly0A",
				"version": {
					"created": "7130199"
				}
			}
		}
	}
}

```

Search request:  
POST test\_index/\_search

```auto
{
	"query": {
		"query_string": {
			"query": "root AND nested"
		}
	},
	"size": 10,
	"from": 0,
	"sort": []
}

```

Response:

```auto
{
	"took": 2,
	"timed_out": false,
	"_shards": {
		"total": 1,
		"successful": 1,
		"skipped": 0,
		"failed": 0
	},
	"hits": {
		"total": {
			"value": 0,
			"relation": "eq"
		},
		"max_score": null,
		"hits": []
	}
}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 1, 2021, 7:48pm UTC](https://discuss.elastic.co/t/es-1-7-6-search-within-root-and-nested-objects/277333/2 "2021-07-01T19:48:54Z")

</div>

The document you found in Elasticsearch 1.7 was of type `doc`. If you look at the mappings you have not specified `"type": "nested"` for this but you have done so for the Elasticsearch 7.13 mapping. As the mapping is different you get different results.

---

<div class="post-metadata">

**Author:** ![ValeryL](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@ValeryL](https://discuss.elastic.co/u/ValeryL)\
**Post date:** [July 2, 2021, 7:40am UTC](https://discuss.elastic.co/t/es-1-7-6-search-within-root-and-nested-objects/277333/3 "2021-07-02T07:40:51Z")

</div>

Thank you, really appreciate your help. I tried to change the index mapping for Elasticsearch 1.7 to the following, but I still can get search result for both root and nested fields, my understanding, it should not work, but it does 🙂 )

ES 1.7 index mapping

```auto
{
	"test_index_new": {
		"aliases": {},
		"mappings": {
			"objects": {
				"properties": {
					"nested_field": {
						"type": "nested",
						"properties": {
							"nested_field_one": {
								"type": "string",
								"fields": {
									"raw": {
										"type": "string"
									}
								}
							}
						}
					},
					"root_field_one": {
						"type": "string",
						"fields": {
							"raw": {
								"type": "string"
							}
						}
					}
				}
			}
		},
		"settings": {
			"index": {
				"creation_date": "1625209549926",
				"number_of_shards": "5",
				"number_of_replicas": "1",
				"version": {
					"created": "1070699"
				},
				"uuid": "bDz3J4wURVGwUT04Iq0ZcA"
			}
		},
		"warmers": {}
	}
}

```

Search request:

```auto
{
	"query": {
		"query_string": {
			"query": "nested AND root"
		}
	},
	"size": 10,
	"from": 0,
	"sort": []
}

```

Response:

```auto
{
	"took": 1,
	"timed_out": false,
	"_shards": {
		"total": 5,
		"successful": 5,
		"failed": 0
	},
	"hits": {
		"total": 1,
		"max_score": 0.53033006,
		"hits": [
			{
				"_index": "test_index_new",
				"_type": "objects",
				"_id": "1",
				"_score": 0.53033006,
				"_source": {
					"nested_field": [
						{
							"nested_field_one": "nested field text"
						}
					],
					"root_field_one": "root field text"
				}
			}
		]
	}
}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 2, 2021, 9:59am UTC](https://discuss.elastic.co/t/es-1-7-6-search-within-root-and-nested-objects/277333/4 "2021-07-02T09:59:46Z")

</div>

Then I do not know. Elasticsearch 1.7 is so old that I have not touched it in years. If this was a possible back then or a bug I do not know.

---

<div class="post-metadata">

**Author:** ![ValeryL](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@ValeryL](https://discuss.elastic.co/u/ValeryL)\
**Post date:** [July 2, 2021, 10:18am UTC](https://discuss.elastic.co/t/es-1-7-6-search-within-root-and-nested-objects/277333/5 "2021-07-02T10:18:05Z")

</div>

Yes, it was also my thoughts, bug or not documented feature of Elasticsearch 1.7. Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 30, 2021, 10:18am UTC](https://discuss.elastic.co/t/es-1-7-6-search-within-root-and-nested-objects/277333/6 "2021-07-30T10:18:37Z")

</div>

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