ES 1.7.6 Search within root and nested objects

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

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

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

Response:

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

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

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

Response:

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

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.

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 :slight_smile: )

ES 1.7 index mapping

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

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

Response:

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

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.

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

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