# Nested query and ignore\_unmapped option problem

**URL:** <https://discuss.elastic.co/t/nested-query-and-ignore-unmapped-option-problem/70693>\
**Category:** Elasticsearch\
**Created:** [January 5, 2017, 3:15pm UTC](https://discuss.elastic.co/t/nested-query-and-ignore-unmapped-option-problem/70693 "2017-01-05T15:15:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![psu](https://avatars.discourse-cdn.com/v4/letter/p/cc9497/32.png) [@psu](https://discuss.elastic.co/u/psu)\
**Post date:** [January 5, 2017, 3:15pm UTC](https://discuss.elastic.co/t/nested-query-and-ignore-unmapped-option-problem/70693/1 "2017-01-05T15:15:04Z")

</div>

Hi there

I'm trying to make a search query to 2 slightly different indexes simultaneously. One of them contains field of nested type, another does not. So I add 'ignore\_unmapped' option to nested query to avoid exception but this does not help. I'm using elasticsearch version 5.0.

Here is part of the query

```
'bool' => array(
	'filter' => array(
		array( 'term' => array( '_index' => 'index_with_nested_field' ) ),
	),
	'should' => array(
		array(
			'nested' => array(
				'ignore_unmapped' => true,
				'path' => 'NESTED_FIELD',
				'query' => array(
					'function_score' => array(
						'functions' => array(
							array(
								'filter' => array(
									'bool' => array(
										'must' => array(
											array( 'term' => array( 'NESTED_FIELD.sub1' => 0 ) ),
											array( 'range' => array( 'NESTED_FIELD.sub2' => array( 'gt' => 3 ) ) )
										)
									),
								),
								'weight' => -10,
							)

```

and the query URI looks like this

/index\_with\_nested\_field,index\_without\_nested\_field/\_search...

and part of the error looks like this

'index' =\> string 'index\_without\_nested\_field' (length=18)  
'caused\_by' =\>  
array (size=2)  
'type' =\> string 'illegal\_state\_exception' (length=23)  
'reason' =\> string '[nested] failed to find nested object under path [NESTED\_FIELD]'

If I remove functions part of the query it works fine, so seems it ignores ignore\_unmapped option.  
Please advise.

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [January 5, 2017, 5:35pm UTC](https://discuss.elastic.co/t/nested-query-and-ignore-unmapped-option-problem/70693/2 "2017-01-05T17:35:36Z")

</div>

Hi @psu,

unfortunately, this turns out to be a bug. It happens when the query needs to get rewritten internally, which is the case for the range query part. So if you remove just the range query part, it should work.

We'll fix this issue and when the Github ticket is available I'll post it here for reference.

Daniel

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [January 5, 2017, 10:22pm UTC](https://discuss.elastic.co/t/nested-query-and-ignore-unmapped-option-problem/70693/3 "2017-01-05T22:22:53Z")

</div>

Thanks for reporting this bug @psu!  
I've opened a PR that fixes this: [https://github.com/elastic/elasticsearch/pull/22456](https://github.com/elastic/elasticsearch/pull/22456)

---

<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:** [February 2, 2017, 10:22pm UTC](https://discuss.elastic.co/t/nested-query-and-ignore-unmapped-option-problem/70693/4 "2017-02-02T22:22:53Z")

</div>

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