elasticsearch

운영자 | 기사입력 2018/10/08 [07:43]
>
필자의 다른기사 보기 인쇄하기 메일로 보내기 글자 크게 글자 작게
elasticsearch
 
운영자   기사입력  2018/10/08 [07:43]

 elasticsearch/config/elasticsearch.yml

 

path.repo: ["/home/backup"] 

 

 

  PUT /_snapshot/my_backup

        {

          "type": "fs",

"settings": {

            "compress": true,

"location": "/home/backup"

           }

 

         }

=================

{

  "error": {

    "root_cause": [

      {

        "type": "exception",

        "reason": "failed to create blob container"

      }

    ],

    "type": "exception",

    "reason": "failed to create blob container",

    "caused_by": {

      "type": "access_denied_exception",

      "reason": "/home/backup/tests-U83WymyGR4Gu6kqW_4OWcQ"

    }

  },

  "status": 500

}

======================

chown elasticsearch:elasticsearch /home/backup

 

 

{

  "acknowledged" : true

}

 

 

PUT /_snapshot/my_backup/test-2018.12.06?wait_for_completion=true

{

  "indices": "ins_wave_count2",

  "ignore_unavailable": true,

  "include_global_state": false

}

 

====================================

database   index

table       type

row        document

column       field

index          everything is indexed

sql            queryDSL

 

 

curl -XGET http://192.168.0.43:9200/classes

{"classes":{"aliases":{},"mappings":{},"settings":{"index":{"creation_date":"1538981707376","number_of_shards":"5","number_of_replicas":"1","uuid":"fB5lfXyQTjS66G4IaCmHWg","version":{"created":"6040199"},"provided_name":"classes"}}}}[root@s201809 ~]# 

 

 

 

index 생성

 

 

 curl -XPUT http://192.168.0.43:9200/classes

 

{"error":"Incorrect HTTP method for uri [/classes] and method [POST], allowed: [GET, HEAD, DELETE, PUT]","status":405}[root@s201809 ~]# 

 

 

Document create 

 

 

curl -XPUT -H 'Content-Type: application/json' http://192.168.0.43:9200/classes/class/1 -d '{"title":"aaaa","body":"bbbb"}'

{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

 

 

http://192.168.0.43:9200/classes?pretty

 

 

 

==============================================================

./elasticsearch

Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

Java HotSpot(TM) 64-Bit Server VM warning: UseAVX=2 is not supported on this CPU, setting it to UseAVX=0

[2018-12-10T17:35:12,259][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]

org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.5.2.jar:6.5.2]

        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.2.jar:6.5.2]

        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.2.jar:6.5.2]

        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.2.jar:6.5.2]

        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.2.jar:6.5.2]

        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.2.jar:6.5.2]

        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.2.jar:6.5.2]

Caused by: java.lang.RuntimeException: can not run elasticsearch as root

        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.2.jar:6.5.2]

        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.2.jar:6.5.2]

        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.2.jar:6.5.2]

        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.2.jar:6.5.2]

 

 ./elasticsearch

 

java.lang.RuntimeException: can not run elasticsearch as root

 

 

useradd   elasticsearch

 

chown elasticsearch:elasticsearch  elasticsearch -R

 

./bin/elasticsearch &

 

 

PUT /inswave?pretty

GET /_cat/indices?v

 

 

 config/elasticsearch.yml

network.host: 0.0.0.0

 

 

 

./bin/elasticsearch-plugin install   file:///home/elasticsearch-6.6.2/elasticsearch-analysis-seunjeon-6.1.1.0.zip 

-> Downloading file:///home/elasticsearch-6.6.2/elasticsearch-analysis-seunjeon-6.1.1.0.zip

[=================================================] 100%혻혻 

ERROR: This plugin was built with an older plugin structure. Contact the plugin author to remove the intermediate "elasticsearch" directory within the plugin zip.

 

 

wget https://bitbucket.org/eunjeon/seunjeon/raw/master/elasticsearch/scripts/downloader.sh

 

chmod 755 downloader.sh

./downloader.sh  -e 6.1.1 -p 6.1.1.1

 

  에러 나오면  

./downloader.sh: line 74: zip: command not found

 yum -y install zip

 

 

 

./bin/elasticsearch-plugin install  analysis-nori

 

로리 플러스인 설치 

 

 

 

 

ERROR: [4] bootstrap checks failed

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

[2]: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [4096]

[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

 

vim /etc/security/limits.conf 

 

*                 soft    nofile           99192

*                 hard    nofile           99192

 

 

sysctl -w vm.max_map_count=262144 

 

vi /etc/security/limits.conf

 

elastic hard nofile 65536

elastic soft nofile 65536

elastic hard nproc 65536

elastic soft nproc 65536

root hard nofile 65536

root soft nofile 65536

root hard nproc 65536

root soft nproc 65536

 

 

 

ERROR: [1] bootstrap checks failed

 

system call filters failed  

 

bootstrap.system_call_filter: false 

 

 /home/elasticsearch-6.6.2/config/elasticsearch.yml

 

 

curl -XPUT -H 'Content-Type: application/json' http://192.168.0.43:9200/classes/class/1 -d '{"title":"aaaa","body":"bbbb"}'

 

 

curl -XGET "http://localhost:9200/classes/class/1"

 

curl -XGET "http://localhost:9200/classes/class/_search"

 

curl -XGET "http://localhost:9200/classes/class/1?_source=title"

 

curl -XGET "http://localhost:9200/classes/class/_search?q=title:aaaa"

 

 

 

curl -XGET "http://localhost:9200/classes/class/_search?q=title:*aaaa*"

 

 

삭제 

curl -XDELETE "http://localhost:9200/classes/class/1"

 

 

curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/inswave/insnews/1 -d '{"title":"aaaa","body":"bbbb"}'

 

 

curl -XDELETE "http://localhost:9200/inswave/insnews/1"

 

curl -XGET "http://localhost:9200/inswave/insnews/_search"

 

 

 

### 인덱스 생성

 

index명: indexnews

 

type명: typenews

 

뉴스기사의 title과 summary 는 nori로 형태소 분석을 하고 link, 매체명은 형태소 분석없이 그대로 인덱싱.

 

만약 아래 코드를 그대로 입력하면 에러가 나며 설치되지 않는다. 사용자사전(userdic_ko.txt)을 생성한 후 실행한다. 에러날때 위치가 나타나므로 참고해도 되고, 통상 config 아래 생성하면 된다.

 

 

index 생성 

 

curl -XPUT -H 'Content-Type: application/json'   http://localhost:9200/test1

 

index 삭제 

 

curl -XDELETE -H 'Content-Type: application/json'   http://localhost:9200/test1

 

 

별도의 json 파일 생성 후 index 생성 

 

curl -s -XPUT -H 'Content-Type: application/json' http://localhost:9200/test1/ -d @ 1.json

 

 

index 생성 확인  _mapping

{

 

  "settings": {

 

    "index": {

 

      "number_of_shards": "1",

 

      "number_of_replicas": "0",

 

      "analysis": {

 

        "analyzer": {

 

          "nori": {

 

            "filter": ["pos_filter", "lowercase", "nori_readingform"],

 

            "tokenizer": "nori_user_dict"

 

          }

 

        },

 

        "tokenizer":{

 

          "nori_user_dict": {

 

            "mode": "MIXED",

 

            "type": "nori_tokenizer",

 

            "user_dictionary": "userdic_ko.txt"

 

          }

 

        },

 

        "filter": {

 

          "pos_filter": {

 

            "type": "nori_part_of_speech",

 

            "stoptags": [

 

              "E", "IC", "J", "MAG", "SP", "SSC", "SSO", "SC", "SE", "XPN", "XSA", "XSN", "XSV", "UNA", "NA", "VSV"

 

              ]

 

          }

 

        }

 

      }

 

 

 

    }

 

  },

 

  "mappings" : {

 

    "insnews" : {

 

      "properties" : {

 

        "title" : { 

 

          "type": "text",

 

          "analyzer": "nori",

 

          "fielddata": true                

 

                },

 

 

        "body" : { 

 

          "type": "text",

 

          "analyzer": "nori",

 

          "fielddata": true                

 

                },

 

        "name" : { 

 

                    "type" : "keyword" 

 

                },

 

        "stitle" : { 

 

                    "type" : "keyword" 

 

                },

 

        "domain" : { 

 

                    "type" : "keyword" 

 

                },

         "site_name" : { 

 

                    "type" : "keyword" 

 

                },

 

      

         "img_url" : { 

 

                    "type" : "text" 

 

                },

 

"o_url" : { 

 

                    "type" : "text" 

 

                },

 

        "wdate" : { 

 

                    "type" : "integer" 

 

                },

 

        "o_uid" : { 

 

                    "type" : "integer" 

 

                }

 

      }

 

    }

 

  }

 

}

 

curl -XGET 'localhost:9200/my_index/my_type/_search'-d '{    "query" : {        "match" : {            "testField" : "abc"        }    }}'
========================================
$postParam = array("query"=>array("match"=>array( "title"=>"남양주시" ) ) );




https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_search_operations.html#_match_query
트위터 트위터 페이스북 페이스북 카카오톡 카카오톡
기사입력: 2018/10/08 [07:43]  최종편집: ⓒ iwav