es之ingest、pipeline、painless

一,injest pipeline

// 测试
POST _ingest/pipeline/_simulate
{
  
   "pipeline":{
     "description":"split tags",
     "processors": [
        {
          "split":{
            "field":"tags",
            "separator":","
          }
        }
      ]
   },
   "docs":[
       {
         "index":"index",
         "_id":"id",
         "_source":{
           "tags":"elastic,hadoop,elastic"
         }
       }
    ]
}
//创建
PUT _ingest/pipeline/blog_pipeline
{
  
     "description":"split tags",
     "processors": [
        {
          "split":{
            "field":"tags",
            "separator":","
          }
        }
      ]
   
}
// 测试创建的pipeline
POST _ingest/pipeline/blog_pipeline/_simulate
{
   "docs":[
       {
         "index":"index",
         "_id":"id",
         "_source":{
           "tags":"elastic,hadoop,elastic"
         }
       }
    ]
}
POST my_blog/_doc/?pipeline=blog_pipeline
{
  "tags":"android,java"
}


POST my_blog/_doc/
{
  "tags":"android,java"
}

// 更新数据
POST my_blog/_update_by_query?pipeline=blog_pipeline
{
  "query":{
    "bool": {
      "must":{
        "term":{
           "_id" : "kMiLWXIBgW5fcfR1lXxN"
        }
      }
    }
  }
}

三,painless

es之ingest、pipeline、painless_第1张图片
1, 在update中使用脚本

POST users/_update/5
{
  "script":{
    "source": "ctx._source.age += params.new_age",
    "params": {
      "new_age":5
    }
  }
}

2,在query中使用脚本

GET users/_search/
{
  "query": {
    "term": {
      "_id": {
        "value": "1"
      }
    }
  }, 
  "script_fields": {
    "rnd_age": {
      "script": {
        "lang": "painless",
        "source": """
            java.util.Random r = new Random();
            doc['age'].value + r.nextInt(100); 
        """
      }
    }
  }
}

3,在pipeline中使用

POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "description": "tag splitddd",
    "processors": [
      {
        "split": {
          "field": "tags",
          "separator": ","
        }
      },
      {
        "script": 
          """
            if(ctx.containsKey("mm")) {
              ctx.mm_len = ctx.mm.length();
            }else {
              ctx.mm_len = 0;
            }
          """
        
      }
    ]
  },
   
  "docs":[
       {
         "index":"index",
         "_source":{
            "mm":"1111",
            "tags":"1,2,3,4"
         }
       }
    ]
    
}

你可能感兴趣的:(java)