简体   繁体   English

脚本字段Kibana无法正常工作

[英]Scripted Field Kibana Not Working

I am trying to get scripted fields in Kibana to work. 我正在尝试使Kibana中的脚本字段起作用。

I have two fields in my documents, customer and site 我的文档中有两个字段, customersite

I'd like to create a new scripted field called friendly_name which is customer+" "+site 我想创建一个名为friendly_name的新脚本字段,该字段是customer+" "+site

I've tried return doc["customer"].value + " "+doc["site"].value 我尝试过return doc["customer"].value + " "+doc["site"].value

and it doesn't yield any results. 它不会产生任何结果。

I've even tried just return 1 to see if I can get anything to return. 我什至尝试return 1来查看是否可以返回任何东西。

Kibana脚本字段

How can I get this to work? 我该如何工作?

Scripted fields work with doc_values only and I am guessing that, since this doesn't work for you, your customer and site field are text fields. 脚本字段仅与doc_values一起使用,我猜想,由于这不适用于您,因此customersite字段是text字段。 From https://www.elastic.co/blog/using-painless-kibana-scripted-fields : https://www.elastic.co/blog/using-painless-kibana-scripted-fields

Both Painless and Lucene expressions operate on fields stored in doc_values. 无痛和Lucene表达式都对doc_values中存储的字段进行操作。 So for string data, you will need to have the string to be stored in data type keyword. 因此,对于字符串数据,您将需要将字符串存储在data type关键字中。

So, you either define your two fields to be keyword or you add a subfield to them and in your scrip you use customer.keyword and site.keyword . 因此,您可以将两个字段定义为keyword或者向它们添加一个子字段,并在site.keyword使用customer.keywordsite.keyword And the changed mapping should be: 更改后的映射应为:

      "customer": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM