@@ -169,6 +169,15 @@ private String jsonStringFormat(String value) {
169169 return jsonStringQuote (jsonStringEscape (value ));
170170 }
171171
172+ private boolean indexFieldHasMatcher (String indexName , String indexFieldName ) {
173+ String matcherName = this .model .indices ().get (indexName ).fields ().get (indexFieldName ).matcher ();
174+ if (matcherName == null )
175+ return false ;
176+ if (this .model .matchers ().get (matcherName ) == null )
177+ return false ;
178+ return true ;
179+ }
180+
172181 /**
173182 * Determine if we can construct a query for a given resolver on a given index with a given input.
174183 * Each attribute of the resolver must be mapped to a field of the index and have a matcher defined for it.
@@ -199,7 +208,7 @@ private boolean canQuery(String indexName, String resolverName) {
199208 // The index field must have a matcher defined for it.
200209 boolean hasMatcher = false ;
201210 for (String indexFieldName : this .model .indices ().get (indexName ).attributeIndexFieldsMap ().get (attributeName ).keySet ()) {
202- if (this .model . indices (). get ( indexName ). fields (). get ( indexFieldName ). matcher () != null ) {
211+ if (this .indexFieldHasMatcher ( indexName , indexFieldName )) {
203212 hasMatcher = true ;
204213 break ;
205214 }
@@ -280,8 +289,7 @@ private void traverse() throws IOException, ValidationException {
280289 for (String indexFieldName : this .model .indices ().get (indexName ).attributeIndexFieldsMap ().get (attributeName ).keySet ()) {
281290
282291 // Can we use this index field?
283- boolean hasMatcher = this .model .indices ().get (indexName ).fields ().get (indexFieldName ).matcher () != null ;
284- if (!hasMatcher )
292+ if (!this .indexFieldHasMatcher (indexName , indexFieldName ))
285293 continue ;
286294
287295 // Construct a clause for each input value for this attribute.
@@ -381,20 +389,24 @@ private void traverse() throws IOException, ValidationException {
381389 TreeMap <String , JsonNode > docAttributes = new TreeMap <>();
382390 for (String indexFieldName : this .model .indices ().get (indexName ).fields ().keySet ()) {
383391 String attributeName = this .model .indices ().get (indexName ).fields ().get (indexFieldName ).attribute ();
392+ if (this .model .attributes ().get (attributeName ) == null )
393+ continue ;
384394 String attributeType = this .model .attributes ().get (attributeName ).type ();
395+ if (!nextInputAttributes .containsKey (attributeName ))
396+ nextInputAttributes .put (attributeName , new HashSet <>());
385397 // The index field name might not refer to the _source property.
386398 // If it's not in the _source, remove the last part of the index field name from the dot notation.
387399 // Index field names can reference multi-fields, which are not returned in the _source.
388- if (! nextInputAttributes . containsKey ( attributeName ))
389- nextInputAttributes . put ( attributeName , new HashSet <>() );
390- if (! doc .get ("_source" ).has ( indexFieldName ))
391- indexFieldName = indexFieldName . split ( " \\ ." )[ 0 ];
392- if ( doc .get ("_source" ).has ( indexFieldName )) {
393- JsonNode valueNode = doc . get ( "_source" ). get ( indexFieldName );
394- docAttributes . put ( attributeName , valueNode ) ;
395- Object value = Attribute . convertType ( attributeType , valueNode );
396- nextInputAttributes . get ( attributeName ). add ( value );
397- }
400+ String path = this . model . indices (). get ( indexName ). fields (). get ( indexFieldName ). path ();
401+ String pathParent = this . model . indices (). get ( indexName ). fields (). get ( indexFieldName ). pathParent ( );
402+ JsonNode valueNode = doc .get ("_source" ).at ( path );
403+ if ( valueNode . isMissingNode ())
404+ valueNode = doc .get ("_source" ).at ( pathParent );
405+ if ( valueNode . isMissingNode ())
406+ continue ;
407+ docAttributes . put ( attributeName , valueNode );
408+ Object value = Attribute . convertType ( attributeType , valueNode );
409+ nextInputAttributes . get ( attributeName ). add ( value );
398410 }
399411
400412 // Modify doc metadata.
0 commit comments