Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

elasticsearch painless - Kibana won't allow a calculated field on an optional value, is there a work-around?

I want to display images for objects I have in my index. If an object has a message.media.photo.id object, then it's URL will be http://myserver/content/photos/<id>.jpg.

The problem is that not every message has an a photo object. If the object does not have a message.media.photo or a message.media object then the value of my URL should be Null.

I'm trying to add a Kibana calculated field as follows:

Language: painless
Type: string
Format default: Url
Url Template: /content/photos/{{value}}.jpg
Label template: <blank>

The way to get the id of an image is to look in the field message.media.photo.id, so my first guess is that this Painless expression ought to work:

doc['message.media.photo.id'].value

I get the error message: "Script is invalid. View script preview for details", but there's no details to be seen in the script preview (whatever that is), nor are there any error messages to tell me what might be going wrong.

However the following two expressions do work, produce sensible output (but unfortunately aren't helpful because they are using the wrong IDs).

doc['message.id'].value
doc['id'].value

Could it be that these last two work because every document has an id and every document has a message. Not every message has media and not every media is a photo.

Is there a way to solve this? I only need these photo records for documents that actually have photos.

question from:https://stackoverflow.com/questions/65836181/kibana-wont-allow-a-calculated-field-on-an-optional-value-is-there-a-work-arou

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...