elasticsearch에서 pagination을 하고 싶다면, search_after를 사용한다.


https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html


위 url에서 제공하는 간단한 예제는 다음과 같다. 


GET twitter/tweet/_search

{
    "size": 10,
    "query": {
        "match" : {
            "title" : "elasticsearch"
        }
    },
    "search_after": [1463538857, "654323"],
    "sort": [
        {"date": "asc"},
        {"_id": "desc"}
    ]
}






여러 날짜별로 분리된 인덱스에서도 search_after를 사용할 수 있다.  


다음 예제는 search_after를 활용할 수 있도록 2개의 필드로 소팅하고 2개의 특정 값으로 pagination하는 예제이다. 




curl -XGET 'http://search.google.io:9200/plus.-*/_search?pretty' -H 'Content-Type: application/json' -d'

{  

   "version":true,

   "query":{  

      "bool":{  

         "must":[  

            {  

               "match_all":{        }

            },

            {  

               "range":{  

                  "@timestamp":{  

                     "gte":"2018-01-31T16:52:07+09:00",

                     "lte":"2018-01-31T17:52:07+09:00"

                  }

               }

            }

         ]

      }

   },

   "size":11,

   "sort":[  

      {  

         "@timestamp":{  

            "order":"desc"

         }

      },

      {  

         "_uuid.keyword":{  

            "order":"asc"

         }

      }

   ]

}

'



curl -XGET 'http://search.google.io:9200/plus-*/_search?pretty' -H 'Content-Type: application/json' -d'

{  

   "version":true,

   "query":{  

      "bool":{  

         "must":[  

            {  

               "match_all":{  


               }

            },

            {  

               "range":{  

                  "@timestamp":{  

                     "gte":"2018-01-31T16:52:07+09:00",

                     "lte":"2018-01-31T17:52:07+09:00"

                  }

               }

            }

         ]

      }

   },

   "size":11,

   "search_after":[  

      "1517388213000",

      "f938251211a3"

   ],

   "sort":[  

      {  

         "@timestamp":{  

            "order":"desc"

         }

      },

      {  

         "_uuid.keyword":{  

            "order":"asc"

         }

      }

   ]

}

'




Posted by '김용환'
,



ansible의 become은 sudo를 사용할 수 없이 실제 해당 유저로 로그인함을 의미한다.


http://docs.ansible.com/ansible/latest/become.html



ansible 예제처럼 특정 사용자로 인증 후 사용될 수 있다.


- name: Run a command as the apache user
  command: somecommand
  become: true
  become_user: apache




만약 root로 접근하고 싶다면, 미리 장비에서 root로 접근할 수 있는 설정이 되어 있어야 잘 동작한다.


www@aaa~$ sudo -i

root@aaa:~#



다음은 playbook 예제이다.




- name: create /home/www

  become: yes

  become_method: sudo

  file: path=/home/www state=directory owner=www group=www




- hosts: webservers

  tasks:

    - service: name=nginx state=started

      become: yes

      become_method: sudo



Posted by '김용환'
,




ansible-playbook을 실행하다가 ERROR! Specified --limit does not match any hosts 에러가 발생했다.


$ ansible-playbook -i test-stats docker.yml 


호스트 설정이 빠져서 발생한 것이니. host 설정을 살펴본다.


[docker] 

abc.test01.i.google.com



Posted by '김용환'
,