Nested query and ignore_unmapped option problem


#1

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.


Nested Query Against Different Index Mappings using ignore_unmapped
(Daniel Mitterdorfer) #2

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


(Martijn Van Groningen) #3

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


(system) #4

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