Hi Kibana Jedi Masters,
Suppose I have a Kibana data chart Visualisation tracking the inventory of my fruit store:
| Product Code | Qnty | ========================= | 100 | 15 | | 400 | 8 | | 200 | 20 | | 500 | 6 |
Every kind of fruit is tracked by a hard-to-remember Product Code. On a separate data source - not within an Elasticsearch index - I have the Product Code-to-fruit mapping:
| Product Code | Name | ========================== | 100 | Apples | | 200 | Oranges | | 300 | Bananas |
You see where this is going; I need to modify the original data chart to be this:
| Product Code | Name | Qnty | =================================== | 100 | Apples | 15 | | 400 | (unknown) | 8 | | 200 | Bananas | 20 | | 500 | (unknown) | 6 |
I originally thought I could do this with a Scripted Field, where:
Name: FruitName Language: painless Type: string Format: Default Popularity: 0 Script: IF doc['ProductCode'].value == 100 then "Apples" ELSE IF doc['ProductCode'].value == 200 then "Oranges" ELSE IF doc['ProductCode'].value == 300 then "Bananas" ELSE "(unknown)"
The above generates syntax errors, obviously. I could figure out and fix them, but this whole approach seems pretty unwieldy to me. The Product Codes/Fruit Name list could have hundreds of items, possibly more. From a coding perspective, I don’t like the idea of running so many If/Else comparisons for every individual data record.
A much better solution would be the way they do it in SQL-like databases: The original inventory would be in one data chart, and the Product Codes/Fruit Name list would be in a separate table, somewhere in Elasticsearch or Kibana, I guess. When Kibana goes to generate the inventory chart, it would cross-reference both lists to populate the “Name” column.
Is there a tutorial that shows how to do this? Or can someone suggest how I can start? Thanks!