A few Painless questions


#1

I'm trying to get a better understanding of Painless and one thing that seems unclear to me is the doc field:

  1. What is the difference between doc['field_name'] and doc['field_name'].value?
  2. Do I access nested fields like doc['field_name']['nested_field'] or doc['field_name.nested_field']?
  3. I'm kind of unclear on how to use the Painless API page to find methods and properties available for certain data types. For example, I know you can use [3,4,5].length, but can you use length on maps as well as arrays? I see in the docs I can use add() to add a value to an array, but can I do that with Maps too? What other functions are available? The API page seems hard for me to figure this out.

(Ryan Ernst) #2
  1. doc['field_name'] returns an accessor for the field, .value actually gets the value for the field
  2. `doc['field_name.nested_field'] is the correct syntax. Note that I only used your terminology here, but nested documents are not accessible (these are indexed as separate documents in lucene).
  3. Painless is really just java with a couple groovy-like syntax features. So you should look at Java. The "array" you have there is actually an ArrayList, which is why you can call add on it. I don't know what to tell you other than if you can write java code, it should work, so look for java examples if in doubt.

(system) #3

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