'script'에 해당되는 글 8건

  1. 2022.11.23 [Elasticsearch] Accessing document field on scripts
  2. 2022.08.17 [Shell Script] bash script background run
  3. 2021.12.30 [Bash] jq -r raw output (no quote)
  4. 2020.06.17 [Elasticsearch] script 사용 시 "#! Deprecation: Deprecated field [inline] used, expected [source] instead"
  5. 2020.04.07 [Kibana] Visualize Metric JSON Input 예제
  6. 2018.02.13 [Script] uniq string line print on shell
  7. 2017.02.01 [Kibana] Metric 내 script 사용 예제
  8. 2016.08.03 [Bash Script] ssh 접속 시 hostname 기준으로 편하게 사용하기.

[Elasticsearch] Accessing document field on scripts

Elastic/Elasticsearch 2022. 11. 23. 17:08

아는 것도 시간이 지나면 다 까먹는 나이!!

 

[레퍼런스]

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-fields.html#_search_and_aggregation_scripts
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-expression.html

 

접근 유형에 따른 성능)

doc value 가 가장 빠르고 _source 와 _fields 는 비슷 합니다.

 

QueryDSL 예제)

GET /kibana_sample_data_ecommerce/_search
{
  "query": {
    "script_score": {
      "query": {
        "bool": {
          "filter": {
            "term": {
              "products.product_name": "shirt"
            }
          }
        }
      },
      "script": {
          "lang": "expression",
          "source": "_score * doc['taxless_total_price']"
        }
    }
  }
}

GET /kibana_sample_data_ecommerce/_search
{
  "query": {
    "script_score": {
      "query": {
        "bool": {
          "filter": {
            "term": {
              "products.product_name": "shirt"
            }
          }
        }
      },
      "script": {
          "lang": "painless",
          "source": "_score * doc['taxless_total_price'].value"
        }
    }
  }
}

GET /kibana_sample_data_ecommerce/_search
{
  "query": {
    "script_score": {
      "query": {
        "bool": {
          "filter": {
            "term": {
              "products.product_name": "shirt"
            }
          }
        }
      },
      "script": {
          "lang": "painless",
          "source": "_score * params._source.taxless_total_price"
        }
    }
  }
}

expression 과 painless 에 따라 다르기 때문에 사용에 주의 하세요.

:

[Shell Script] bash script background run

ITWeb/개발일반 2022. 8. 17. 19:21
$ bash run.sh 1>/dev/null 2>&1 &

$ bash run.sh >/dev/null 2>&1 & echo $! > run.pid

background 실행 및 pid 활용.

 

:

[Bash] jq -r raw output (no quote)

ITWeb/개발일반 2021. 12. 30. 16:25

이런 것도 기억력 도움을 위해서 그냥 한 줄 남겨 봅니다.

 

$ jq .hits.total.relation 하면 

Output)

"eq"

이렇게 나오는데 저는 저 quotation 이 싫습니다.

 

그래서 아래 옵션 주고 하시면 됩니다.

 

$ jq -r .hits.total.relation

Output)

eq

 

:

[Elasticsearch] script 사용 시 "#! Deprecation: Deprecated field [inline] used, expected [source] instead"

Elastic/Elasticsearch 2020. 6. 17. 08:20

에러 메시지를 보면 답이 나와 있습니다.

inline 대신 source 를 사용 하라는 이야기 입니다.

 

[ASIS]

  "aggs": {
    "3": {
      "date_histogram": {
        "field": "@timestamp",
        "fixed_interval": "30s",
        "time_zone": "Asia/Seoul",
        "min_doc_count": 1
      },
      "aggs": {
        "1": {
          "max": {
            "field": "system.cpu.total.pct",
            "script": {
              "inline": "doc['system.cpu.total.pct'].value *100",
              "lang": "painless"
            }
          }
        }
      }
    }
  }

 

[TOBE]

  "aggs": {
    "3": {
      "date_histogram": {
        "field": "@timestamp",
        "fixed_interval": "30s",
        "time_zone": "Asia/Seoul",
        "min_doc_count": 1
      },
      "aggs": {
        "1": {
          "max": {
            "field": "system.cpu.total.pct",
            "script": {
              "source": "doc['system.cpu.total.pct'].value *100",
              "lang": "painless"
            }
          }
        }
      }
    }
  }

이상 끝.

:

[Kibana] Visualize Metric JSON Input 예제

Elastic/Kibana 2020. 4. 7. 20:11

kibana 에서 visualize 중 metric 을 구성 할 때 또는 다른 visualize 이더라도 비슷 합니다.

JSON Input 은 아래와 같이 넣으 실 수 있습니다.

{
  "script": {
    "inline": "doc['system.filesystem.free'].value / 1024 / 1024 /1024",
    "lang": "painless"
  }
}

좀 더 자세한 내용이 궁금 하신 분들은 아래 문서 한번 보시면 좋습니다.

 

공식문서)

https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-fields.html

 

 

:

[Script] uniq string line print on shell

ITWeb/개발일반 2018. 2. 13. 13:26

파일에 id 목록이 들어 있고 여기서 unique 한 id 들만 출력하고 싶을 경우 아래와 같이 사용 하시면 편하게 찾으 실 수 있습니다.


Tips)

$ sort id_list.log | uniq


Ref)

http://www.tutorialspoint.com/unix_commands/sort.htm

http://www.tutorialspoint.com/unix_commands/uniq.htm

:

[Kibana] Metric 내 script 사용 예제

Elastic/Kibana 2017. 2. 1. 17:01

Kibana 에서 visualize 생성 시 metric 영역을 통한 script 사용 초간단 예제 입니다.

참고 하실 문서는 아래 문서 보시면 됩니다.


[참고문서]

https://www.elastic.co/guide/en/kibana/4.6/metric-chart.html


[Script 예제]

{

  "size": 0,

  "query": {

    "filtered": {

      "query": {

        "query_string": {

          "analyze_wildcard": true,

          "query": "*"

        }

      },

      "filter": {

        "bool": {

          "must": [

            {

              "range": {

                "time": {

                  "gte": 1485788400000,

                  "lte": 1485874799999,

                  "format": "epoch_millis"

                }

              }

            }

          ],

          "must_not": []

        }

      }

    }

  },

  "aggs": {

    "2": {

      "terms": {

        "field": "id",

        "size": 5,

        "order": {

          "1": "desc"

        }

      },

      "aggs": {

        "1": {

          "sum": {

            "field": "price",

            "script": "doc['price'].value * doc['count'].value"

          }

        }

      }

    }

  }

}


[Kibana 예제]

"script" : "doc['price'].value * doc['count'].value"

}


:

[Bash Script] ssh 접속 시 hostname 기준으로 편하게 사용하기.

ITWeb/개발일반 2016. 8. 3. 14:37

그냥 노가다 입니다.

ssh 접속 할때 dev/stage/prod 환경으로 각각 접속 할때 hostname 기준으로 하다 보면 매번 입력하기 귀찮은데요.

기억도 나지 않고, 그래서 노가다 스크립트 하나 만들었습니다.


변형해서 사용하거나 그냥 하드코딩 하거나 맘대로 사용하세요.


#!/bin/bash


SUFFIX='web'


echo '1) stage-web'

echo '2) prod-web'

... 중략


read choice


case $choice in

  1)

    SUFFIX='web'

    ;;

  2)

    SUFFIX='irc'

    ;;

... 중략

    ;;

  *)

    echo 'Choice number.'

    exit;

esac


echo "Connecting to ssh {PREFIX-NAME}-$SUFFIX"

sleep 1

ssh {PREFIX-NAME}-$SUFFIX


: