栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

系统学习笔记8-脚本字段简单认识

系统学习笔记8-脚本字段简单认识

    字段设置成 fielddata 为 true
PUT /test
{
  "mappings": {
    "_doc": {
      "properties": {
        "age": {
          "type": "integer"
        },
        "name": {
          "type": "text",
          "fielddata":true,
          "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
        }
      }
    }
  }
}
    插入数据
POST test/_doc/
{
  "name":"apple",
  "age":25
}

自动生成id

    脚本查询
GET test/_doc/_search
{
  "query": {
    "match_all": {}
  },
  "script_fields": {
    "a_filed_name": {
      "script": {
        "lang": "painless",
        "source": "doc['name.keyword'].value+'_hello'"
      }
    }
  }
}
{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "test",
        "_type": "_doc",
        "_id": "KwWH5H4BCls4bvt4nUfz",
        "_score": 1,
        "fields": {
          "a_filed_name": [
            "apple_hello"
          ]
        }
      }
    ]
  }
}

更多资料

https://www.elastic.co/guide/en/elasticsearch/reference/6.3/modules-scripting-painless.htmlhttps://www.elastic.co/guide/en/elasticsearch/painless/6.3/painless-lang-spec.htmlhttps://www.elastic.co/guide/en/elasticsearch/painless/6.3/painless-api-reference.html

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/734685.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号