1

when use doc["abc"],it turns out no field "abc" exception, only to find params._source["abc"] get everything correct.

I checked the status of doc["abc"].value ,it shows null , also doc["abc"].empty is true.

1.elasticsearch version:5.x

2.use painless inline sort script

can anybody figureit out what. happened?

zzzhy
  • 13
  • 1
  • 4

1 Answers1

2

Depending on where a script is used, it will have access to certain special variables and document fields. I dont know your mapping, but i think this link will answer your questions - Accessing document fields and special variables

To quote further from above link:

Doc values and text fields

The doc['field'] syntax can also be used for analyzed text fields if fielddata is enabled, but BEWARE: enabling fielddata on a text field requires loading all of the terms into the JVM heap, which can be very expensive both in terms of memory and CPU. It seldom makes sense to access text fields from scripts.

Doc values are a columnar field value store, enabled by default on all fields except for analyzed text fields.

The _source provides access to the original document body that was indexed (including the ability to distinguish null values from empty fields, single-value arrays from plain scalars, etc).

if your field abc is an analyzed text field or an object, doc wont work.

Polynomial Proton
  • 5,020
  • 20
  • 37
  • Hi @Polynomial Proton, I was trying to access "_source" field using painless script but getting error. If you could check my query my it would be helpful. https://stackoverflow.com/questions/72803840/access-nested-objects-using-painless-for-elasticsearch-opensearch-alerting-to-cr – Divyank Jul 01 '22 at 09:45