├── .gitignore ├── README.md ├── document ├── sample │ ├── chapter03 │ │ ├── 3.1 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ └── 05.txt │ │ ├── 3.2 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ └── 10.txt │ │ ├── 3.3 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ ├── 10.txt │ │ │ └── 11.txt │ │ ├── 3.4 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ ├── 10.txt │ │ │ ├── 11.txt │ │ │ ├── 12.txt │ │ │ ├── 13.txt │ │ │ ├── 14.txt │ │ │ ├── 15.txt │ │ │ ├── 16.txt │ │ │ ├── 17.txt │ │ │ ├── 18.txt │ │ │ ├── 19.txt │ │ │ ├── 20.txt │ │ │ ├── 21.txt │ │ │ ├── 22.txt │ │ │ ├── 23.txt │ │ │ └── synonym.txt │ │ └── 3.5 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ ├── 10.txt │ │ │ ├── 11.txt │ │ │ └── 12.txt │ ├── chapter04 │ │ ├── 4.1 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ └── 06.txt │ │ ├── 4.2 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ ├── 10.txt │ │ │ ├── 11.txt │ │ │ └── 12.txt │ │ ├── 4.3 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ └── 10.txt │ │ └── 4.4 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ └── 10.txt │ ├── chapter05 │ │ ├── 5.1 │ │ │ └── 01.txt │ │ ├── 5.2 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ ├── 10.txt │ │ │ ├── 11.txt │ │ │ ├── 12.txt │ │ │ ├── 13.txt │ │ │ ├── 14.txt │ │ │ ├── 15.txt │ │ │ ├── 16.txt │ │ │ ├── 17.txt │ │ │ ├── 18.txt │ │ │ ├── 19.txt │ │ │ ├── 20.txt │ │ │ ├── 21.txt │ │ │ ├── 22.txt │ │ │ ├── 23.txt │ │ │ ├── 24.txt │ │ │ ├── 25.txt │ │ │ └── 26.txt │ │ ├── 5.3 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ ├── 10.txt │ │ │ ├── 11.txt │ │ │ └── 12.txt │ │ └── 5.4 │ │ │ ├── 01.txt │ │ │ └── 02.txt │ ├── chapter06 │ │ ├── 6.1 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ └── 09.txt │ │ └── 6.2 │ │ │ ├── 01.txt │ │ │ ├── 02.txt │ │ │ ├── 03.txt │ │ │ ├── 04.txt │ │ │ ├── 05.txt │ │ │ ├── 06.txt │ │ │ ├── 07.txt │ │ │ ├── 08.txt │ │ │ ├── 09.txt │ │ │ ├── 10.txt │ │ │ └── 11.txt │ └── chapter07 │ │ ├── 7.1 │ │ ├── 01.txt │ │ ├── 02.txt │ │ ├── 03.txt │ │ ├── 04.txt │ │ ├── 05.txt │ │ └── 06.txt │ │ ├── 7.2 │ │ ├── 01.txt │ │ ├── 02.txt │ │ ├── 03.txt │ │ ├── 04.txt │ │ ├── 05.txt │ │ └── 06.txt │ │ └── 7.3 │ │ ├── 7.3.1 │ │ ├── 01.txt │ │ ├── 02.txt │ │ ├── 03.txt │ │ └── 04.txt │ │ ├── 7.3.3.2 │ │ ├── 01.txt │ │ ├── 02.txt │ │ ├── 03.txt │ │ ├── 04.txt │ │ └── 05.txt │ │ ├── 7.3.3.3 │ │ ├── 01.txt │ │ ├── 02.txt │ │ └── 03.txt │ │ └── 7.3.3.4 │ │ ├── 01.txt │ │ ├── 02.txt │ │ └── 03.txt └── system │ ├── cat │ ├── _cat.txt │ ├── _cat@allocation.txt │ ├── _cat@count.txt │ ├── _cat@fielddata.txt │ ├── _cat@health.txt │ ├── _cat@indices.txt │ ├── _cat@master.txt │ ├── _cat@nodes.txt │ ├── _cat@plugins.txt │ ├── _cat@recovery.txt │ ├── _cat@segments.txt │ ├── _cat@shards.txt │ ├── _cat@tasks.txt │ ├── _cat@templates.txt │ └── _cat@thread_pool.txt │ ├── monitoring │ ├── _cluster@stats.txt │ ├── _node@stats.txt │ ├── _stats(movie).txt │ ├── _stats(news).txt │ └── _stats.txt │ ├── nodeDetail │ ├── _cluster@state.txt │ ├── _nodes(_local).txt │ ├── _nodes.txt │ └── _nodes@usage.txt │ └── rally │ ├── run1.txt │ ├── run2.txt │ └── run3.txt ├── pom.xml └── src └── main └── java └── io └── javacafe └── client ├── rest ├── Example01.java ├── Example02.java ├── Example03.java ├── Example04.java ├── Example05.java ├── Example06.java ├── Example07.java ├── Example08A.java ├── Example08B.java ├── Example08C.java ├── Example09.java ├── Example10.java ├── Example11.java ├── Example12.java ├── Example13.java ├── Example14.java └── Example15.java └── transport ├── Example01.java ├── Example02.java ├── Example03.java ├── Example04.java ├── Example05.java ├── Example06.java ├── Example07.java ├── Example08.java ├── Example09.java ├── Example10.java ├── Example11.java ├── Example12.java ├── Example13.java ├── Example14.java ├── Example15.java ├── Example16.java ├── Example17.java ├── Example18.java ├── Example19.java ├── Example20.java ├── Example21.java ├── Example22.java ├── Example23.java ├── Example24.java ├── Example25.java ├── Example26.java ├── Example27.java ├── Example28.java ├── Example29.java ├── Example30.java ├── Example31.java ├── Example32.java ├── Example33.java ├── Example34.java ├── Example35.java ├── Example36.java ├── Example37.java ├── Example38.java └── Example39.java /.gitignore: -------------------------------------------------------------------------------- 1 | ### Eclipse ### 2 | *.pydevproject 3 | .metadata 4 | .gradle 5 | bin/ 6 | tmp/ 7 | target/ 8 | *.tmp 9 | *.bak 10 | *.swp 11 | *~.nib 12 | local.properties 13 | .settings/ 14 | .loadpath 15 | .factorypath 16 | .classpath 17 | .project 18 | logs/ 19 | work/Tomcat/ 20 | 21 | # Spring 22 | .springBeans 23 | 24 | # External tool builders 25 | .externalToolBuilders/ 26 | 27 | # Locally stored ��Eclipse launch configurations�� 28 | *.launch 29 | 30 | # CDT-specific 31 | .cproject 32 | 33 | # PDT-specific 34 | .buildpath 35 | 36 | # sbteclipse plugin 37 | .target 38 | 39 | # TeXlipse plugin 40 | .texlipse 41 | 42 | ### Maven ### 43 | pom.xml.tag 44 | pom.xml.releaseBackup 45 | pom.xml.versionsBackup 46 | pom.xml.next 47 | release.properties 48 | 49 | ### Java ### 50 | *.class 51 | 52 | # Mobile Tools for Java (J2ME) 53 | .mtj.tmp/ 54 | 55 | # Package Files # 56 | *.jar 57 | *.war 58 | *.ear 59 | 60 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 61 | hs_err_pid* 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # elastic-book 2 | 책에서 사용하는 샘플 예제 3 | 4 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.1/01.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search 3 | { 4 | "settings": { 5 | "number_of_shards": 5, 6 | "number_of_replicas": 1 7 | }, 8 | "mappings": { 9 | "_doc": { 10 | "properties": { 11 | "movieCd": { 12 | "type": "keyword" 13 | }, 14 | "movieNm": { 15 | "type": "text", 16 | "analyzer": "standard" 17 | }, 18 | "movieNmEn": { 19 | "type": "text", 20 | "analyzer": "standard" 21 | }, 22 | "prdtYear": { 23 | "type": "integer" 24 | }, 25 | "openDt": { 26 | "type": "integer" 27 | }, 28 | "typeNm": { 29 | "type": "keyword" 30 | }, 31 | "prdtStatNm": { 32 | "type": "keyword" 33 | }, 34 | "nationAlt": { 35 | "type": "keyword" 36 | }, 37 | "genreAlt": { 38 | "type": "keyword" 39 | }, 40 | "repNationNm": { 41 | "type": "keyword" 42 | }, 43 | "repGenreNm": { 44 | "type": "keyword" 45 | }, 46 | "companies": { 47 | "properties": { 48 | "companyCd": { 49 | "type": "keyword" 50 | }, 51 | "companyNm": { 52 | "type": "keyword" 53 | } 54 | } 55 | }, 56 | "directors": { 57 | "properties": { 58 | "peopleNm": { 59 | "type": "keyword" 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | } 67 | 68 | # 결과 69 | { 70 | "acknowledged" : true, 71 | "shards_acknowledged" : true, 72 | "index" : "movie_search" 73 | } 74 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.1/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | GET movie_search/_mapping 3 | { 4 | "movie_search" : { 5 | "mappings" : { 6 | "_doc" : { 7 | "properties" : { 8 | "companies" : { 9 | "properties" : { 10 | "companyCd" : { 11 | "type" : "keyword" 12 | }, 13 | "companyNm" : { 14 | "type" : "keyword" 15 | } 16 | } 17 | }, 18 | "directors" : { 19 | "properties" : { 20 | "peopleNm" : { 21 | "type" : "keyword" 22 | } 23 | } 24 | }, 25 | "genreAlt" : { 26 | "type" : "keyword" 27 | }, 28 | "movieCd" : { 29 | "type" : "keyword" 30 | }, 31 | "movieNm" : { 32 | "type" : "text", 33 | "analyzer" : "standard" 34 | }, 35 | "movieNmEn" : { 36 | "type" : "text", 37 | "analyzer" : "standard" 38 | }, 39 | "nationAlt" : { 40 | "type" : "keyword" 41 | }, 42 | "openDt" : { 43 | "type" : "integer" 44 | }, 45 | "prdtStatNm" : { 46 | "type" : "keyword" 47 | }, 48 | "prdtYear" : { 49 | "type" : "integer" 50 | }, 51 | "repGenreNm" : { 52 | "type" : "keyword" 53 | }, 54 | "repNationNm" : { 55 | "type" : "keyword" 56 | }, 57 | "typeNm" : { 58 | "type" : "keyword" 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | 66 | 67 | 68 | 69 | 70 | # 요청 71 | PUT movie_search/_doc/1 72 | { 73 | "movieCd": "20173732", 74 | "movieNm": "살아남은 아이", 75 | "movieNmEn": "Last Child", 76 | "prdtYear": "2017", 77 | "openDt": "", 78 | "typeNm": "장편", 79 | "prdtStatNm": "기타", 80 | "nationAlt": "한국", 81 | "genreAlt": "드라마,가족", 82 | "repNationNm": "한국", 83 | "repGenreNm": "드라마", 84 | "directors": [ 85 | { 86 | "peopleNm": "신동석" 87 | } 88 | ], 89 | "companies": [] 90 | } 91 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.1/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_mapping/_mapping/_doc 3 | { 4 | "properties": { 5 | "nationAltEn": { 6 | "type": "text", 7 | "fielddata": true 8 | } 9 | } 10 | } 11 | 12 | # 결과 13 | { 14 | "acknowledged" : true 15 | } 16 | 17 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.1/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT moive_search_mapping 3 | { 4 | "mappings": { 5 | "_doc": { 6 | "properties": { 7 | "awards": { 8 | "type": "text", 9 | "fields": { 10 | "name": { 11 | "type": "keyword" 12 | } 13 | } 14 | } 15 | } 16 | } 17 | } 18 | } 19 | 20 | # 결과 21 | { 22 | "acknowledged" : true, 23 | "shards_acknowledged" : true, 24 | "index" : "moive_search_mapping" 25 | } 26 | 27 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.1/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_mapping/_mapping/_doc 3 | { 4 | "properties": { 5 | "audiCnt": { 6 | "type": "integer", 7 | "null_value": "0" 8 | } 9 | } 10 | } 11 | 12 | # 결과 13 | { 14 | "acknowledged" : true, 15 | "shards_acknowledged" : true, 16 | "index" : "moive_search_mapping" 17 | } 18 | 19 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/01.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST moive_search/_search 3 | { 4 | "size":0, 5 | "aggs": { 6 | "indices": { 7 | "terms": { 8 | "field": "_index", 9 | "size": 10 10 | } 11 | } 12 | } 13 | } 14 | 15 | # 결과 16 | { 17 | "took": 13, 18 | "timed_out": false, 19 | "_shards": { 20 | "total": 5, 21 | "successful": 5, 22 | "skipped": 0, 23 | "failed": 0 24 | }, 25 | "hits": { 26 | "total": 29507, 27 | "max_score": 0, 28 | "hits": [ 29 | 30 | ] 31 | }, 32 | "aggregations": { 33 | "indices": { 34 | "doc_count_error_upper_bound": 0, 35 | "sum_other_doc_count": 0, 36 | "buckets": [ 37 | { 38 | "key": "moive_search", 39 | "doc_count": 29507 40 | } 41 | ] 42 | } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_search 3 | { 4 | "size":0, 5 | "aggs": { 6 | "indices": { 7 | "terms": { 8 | "field": "_type", 9 | "size": 10 10 | } 11 | } 12 | } 13 | } 14 | 15 | # 결과 16 | { 17 | "took": 15, 18 | "timed_out": false, 19 | "_shards": { 20 | "total": 5, 21 | "successful": 5, 22 | "skipped": 0, 23 | "failed": 0 24 | }, 25 | "hits": { 26 | "total": 63069, 27 | "max_score": 0, 28 | "hits": [] 29 | }, 30 | "aggregations": { 31 | "indices": { 32 | "doc_count_error_upper_bound": 0, 33 | "sum_other_doc_count": 0, 34 | "buckets": [ 35 | { 36 | "key": "_doc", 37 | "doc_count": 63069 38 | } 39 | ] 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_search 3 | { 4 | "size":0, 5 | "aggs": { 6 | "indices": { 7 | "terms": { 8 | "field": "_id", 9 | "size": 10 10 | } 11 | } 12 | } 13 | } 14 | 15 | # 결과 16 | { 17 | "took": 5, 18 | "timed_out": false, 19 | "_shards": { 20 | "total": 5, 21 | "successful": 5, 22 | "skipped": 0, 23 | "failed": 0 24 | }, 25 | "hits": { 26 | "total": 63069, 27 | "max_score": 0, 28 | "hits": [] 29 | }, 30 | "aggregations": { 31 | "indices": { 32 | "doc_count_error_upper_bound": 5, 33 | "sum_other_doc_count": 63059, 34 | "buckets": [ 35 | { 36 | "key": "-D3JqmkBjjM-ebDb-U-P", 37 | "doc_count": 1 38 | }, 39 | { 40 | "key": "-D3JqmkBjjM-ebDb-U2P", 41 | "doc_count": 1 42 | }, 43 | { 44 | "key": "-D3JqmkBjjM-ebDb-U6P", 45 | "doc_count": 1 46 | }, 47 | { 48 | "key": "-D3JqmkBjjM-ebDb-UmO", 49 | "doc_count": 1 50 | }, 51 | { 52 | "key": "-D3JqmkBjjM-ebDb-UqP", 53 | "doc_count": 1 54 | }, 55 | { 56 | "key": "-D3JqmkBjjM-ebDb-UuP", 57 | "doc_count": 1 58 | }, 59 | { 60 | "key": "-D3JqmkBjjM-ebDb-UyP", 61 | "doc_count": 1 62 | }, 63 | { 64 | "key": "-D3JqmkBjjM-ebDb-V-P", 65 | "doc_count": 1 66 | }, 67 | { 68 | "key": "-D3JqmkBjjM-ebDb-V2P", 69 | "doc_count": 1 70 | }, 71 | { 72 | "key": "-D3JqmkBjjM-ebDb-V6P", 73 | "doc_count": 1 74 | } 75 | ] 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_search 3 | { 4 | "size":0, 5 | "aggs": { 6 | "indices": { 7 | "terms": { 8 | "field": "_uid", 9 | "size": 10 10 | } 11 | } 12 | } 13 | } 14 | 15 | # 결과 16 | { 17 | "took": 182, 18 | "timed_out": false, 19 | "_shards": { 20 | "total": 5, 21 | "successful": 5, 22 | "skipped": 0, 23 | "failed": 0 24 | }, 25 | "hits": { 26 | "total": 29507, 27 | "max_score": 0, 28 | "hits": [ 29 | 30 | ] 31 | }, 32 | "aggregations": { 33 | "indices": { 34 | "doc_count_error_upper_bound": 5, 35 | "sum_other_doc_count": 29497, 36 | "buckets": [ 37 | { 38 | "key": "_doc#20173732", 39 | "doc_count": 1 40 | } 41 | ] 42 | } 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT reindex_movie 3 | {} 4 | 5 | # 결과 6 | { 7 | "acknowledged": true, 8 | "shards_acknowledged": true, 9 | "index": "reindex_movie" 10 | } 11 | 12 | 13 | 14 | 15 | 16 | # 요청 17 | POST _reindex 18 | { 19 | "source": { 20 | "index": "movie_search", 21 | "query": { 22 | "match": { 23 | "movieCd": "20173732" 24 | } 25 | } 26 | }, 27 | "dest": { 28 | "index": "reindex_movie" 29 | }, 30 | "script": { 31 | "source": "ctx._source.prdtYear++" 32 | } 33 | } 34 | 35 | # 결과 36 | { 37 | "took": 224, 38 | "timed_out": false, 39 | "total": 1, 40 | "updated": 0, 41 | "created": 1, 42 | "deleted": 0, 43 | "batches": 1, 44 | "version_conflicts": 0, 45 | "noops": 0, 46 | "retries": { 47 | "bulk": 0, 48 | "search": 0 49 | }, 50 | "throttled_millis": 0, 51 | "requests_per_second": -1, 52 | "throttled_until_millis": 0, 53 | "failures": [] 54 | } 55 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/06.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_search 3 | { 4 | "query": { 5 | "term": { 6 | "movieCd": "20173732" 7 | } 8 | } 9 | } 10 | 11 | # 결과 12 | { 13 | "took": 2, 14 | "timed_out": false, 15 | "_shards": { 16 | "total": 5, 17 | "successful": 5, 18 | "skipped": 0, 19 | "failed": 0 20 | }, 21 | "hits": { 22 | "total": 1, 23 | "max_score": 9.052594, 24 | "hits": [ 25 | { 26 | "_index": "movie_search", 27 | "_type": "_doc", 28 | "_id": "bzzJqmkBjjM-ebDb8PsR", 29 | "_score": 9.052594, 30 | "_source": { 31 | "movieCd": "20173732", 32 | "movieNm": "살아남은 아이", 33 | "movieNmEn": "Last Child", 34 | "prdtYear": "2017", 35 | "openDt": "", 36 | "typeNm": "장편", 37 | "prdtStatNm": "기타", 38 | "nationAlt": "한국", 39 | "genreAlt": [ 40 | "드라마", 41 | "가족" 42 | ], 43 | "repNationNm": "한국", 44 | "repGenreNm": "드라마", 45 | "directors": [ 46 | { 47 | "peopleNm": "신동석" 48 | } 49 | ], 50 | "companys": [] 51 | } 52 | } 53 | ] 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/07.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST reindex_movie/_search 3 | { 4 | "query": { 5 | "term": { 6 | "movieCd": "20173732" 7 | } 8 | } 9 | } 10 | 11 | # 결과 12 | { 13 | "took": 1, 14 | "timed_out": false, 15 | "_shards": { 16 | "total": 5, 17 | "successful": 5, 18 | "skipped": 0, 19 | "failed": 0 20 | }, 21 | "hits": { 22 | "total": 1, 23 | "max_score": 0.2876821, 24 | "hits": [ 25 | { 26 | "_index": "reindex_movie", 27 | "_type": "_doc", 28 | "_id": "bzzJqmkBjjM-ebDb8PsR", 29 | "_score": 0.2876821, 30 | "_source": { 31 | "movieCd": "20173732", 32 | "movieNm": "살아남은 아이", 33 | "movieNmEn": "Last Child", 34 | "prdtYear": "20171", 35 | "openDt": "", 36 | "typeNm": "장편", 37 | "prdtStatNm": "기타", 38 | "nationAlt": "한국", 39 | "genreAlt": [ 40 | "드라마", 41 | "가족" 42 | ], 43 | "repNationNm": "한국", 44 | "repGenreNm": "드라마", 45 | "directors": [ 46 | { 47 | "peopleNm": "신동석" 48 | } 49 | ], 50 | "companys": [] 51 | } 52 | } 53 | ] 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/08.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT moive_index_meta_fields_all/_doc/20173732 3 | { 4 | "movieCd": "20173732", 5 | "movieNm": "살아남은 아이", 6 | "movieNmEn": "Last Child", 7 | "prdtYear": "2017" 8 | } 9 | 10 | # 결과 11 | { 12 | "_index" : "moive_index_meta_fields_all", 13 | "_type" : "_doc", 14 | "_id" : "20173732", 15 | "_version" : 1, 16 | "result" : "created", 17 | "_shards" : { 18 | "total" : 2, 19 | "successful" : 1, 20 | "failed" : 0 21 | }, 22 | "_seq_no" : 0, 23 | "_primary_term" : 1 24 | } 25 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.2/09.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_routing 3 | { 4 | "settings": { 5 | "number_of_shards": 5, 6 | "number_of_replicas": 1 7 | }, 8 | "mappings": { 9 | "_doc": { 10 | "_routing": { 11 | "required": true 12 | }, 13 | "properties": { 14 | "repGenreNm": { 15 | "type": "keyword" 16 | }, 17 | "movieNm": { 18 | "type": "text" 19 | } 20 | } 21 | } 22 | } 23 | } 24 | 25 | # 결과 26 | { 27 | "acknowledged": true, 28 | "shards_acknowledged": true, 29 | "index": "movie_routing" 30 | } 31 | 32 | 33 | 34 | 35 | 36 | # 요청 37 | PUT movie_routing/_doc/1?routing=ko 38 | { 39 | "repGenreNm": "한국어", 40 | "movieNm": "살아남은 아이" 41 | } 42 | 43 | # 결과 44 | { 45 | "_index": "movie_routing", 46 | "_type": "_doc", 47 | "_id": "1", 48 | "_version": 1, 49 | "result": "created", 50 | "_shards": { 51 | "total": 2, 52 | "successful": 1, 53 | "failed": 0 54 | }, 55 | "_seq_no": 0, 56 | "_primary_term": 1 57 | } 58 | 59 | 60 | 61 | 62 | # 요청 63 | PUT movie_routing/_doc/2?routing=jp 64 | { 65 | "repGenreNm": "일본어", 66 | "movieNm": "공각기동대" 67 | } 68 | 69 | # 결과 70 | { 71 | "_index": "movie_routing", 72 | "_type": "_doc", 73 | "_id": "1", 74 | "_version": 1, 75 | "result": "created", 76 | "_shards": { 77 | "total": 2, 78 | "successful": 1, 79 | "failed": 0 80 | }, 81 | "_seq_no": 0, 82 | "_primary_term": 1 83 | } -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/01.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_datatype 3 | {} 4 | 5 | 6 | 7 | 8 | 9 | 10 | # 요청 11 | PUT movie_search_datatype/_mapping/_doc 12 | { 13 | "properties": { 14 | "multiMovieYn": { 15 | "type": "keyword" 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_text 3 | {} 4 | 5 | 6 | 7 | 8 | 9 | # 요청 10 | PUT movie_text/_mapping/_doc 11 | { 12 | "properties": { 13 | "moiveComment": { 14 | "type": "text" 15 | } 16 | } 17 | } 18 | 19 | 20 | 21 | 22 | 23 | 24 | # 요청 25 | PUT movie_text/_mapping/_doc 26 | { 27 | "properties": { 28 | "moiveComment": { 29 | "type": "text", 30 | "fields": { 31 | "moiveComment_keyword" : { 32 | "type" : "keyword" 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_datatype/_doc/1 3 | { 4 | "title" : "해리포터와 마법사의 돌", 5 | "subtitleLang" : ["ko","en"] 6 | } 7 | 8 | # 결과 9 | { 10 | "_index" : "movie_search_datatype", 11 | "_type" : "_doc", 12 | "_id" : "1", 13 | "_version" : 1, 14 | "result" : "created", 15 | "_shards" : { 16 | "total" : 2, 17 | "successful" : 1, 18 | "failed" : 0 19 | }, 20 | "_seq_no" : 0, 21 | "_primary_term" : 1 22 | } 23 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_text 3 | {} 4 | 5 | # 결과 6 | { 7 | "acknowledged": true, 8 | "shards_acknowledged": true, 9 | "index": "movie_text" 10 | } 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | # 요청 19 | PUT movie_text/_mapping/_doc 20 | { 21 | "properties": { 22 | "year": { 23 | "type": "integer" 24 | } 25 | } 26 | } 27 | 28 | # 결과 29 | { 30 | "acknowledged": true 31 | } 32 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_text 3 | {} 4 | 5 | # 결과 6 | { 7 | "acknowledged": true, 8 | "shards_acknowledged": true, 9 | "index": "movie_text" 10 | } 11 | 12 | 13 | 14 | 15 | 16 | # 요청 17 | PUT movie_text/_mapping/_doc 18 | { 19 | "properties": { 20 | "year": { 21 | "type": "date", 22 | "format": "yyyy-MM-dd HH:mm:ss" 23 | } 24 | } 25 | } 26 | 27 | # 결과 28 | { 29 | "acknowledged": true 30 | } 31 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/06.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_datatype 3 | {} 4 | 5 | # 결과 6 | { 7 | "acknowledged": true, 8 | "shards_acknowledged": true, 9 | "index": "movie_search_datatype" 10 | } 11 | 12 | 13 | 14 | 15 | 16 | # 요청 17 | PUT movie_search_datatype/_mapping/_doc 18 | { 19 | "properties": { 20 | "showRange": { 21 | "type": "date_range" 22 | } 23 | } 24 | } 25 | 26 | # 결과 27 | { 28 | "acknowledged": true 29 | } 30 | 31 | 32 | 33 | 34 | 35 | # 요청 36 | PUT movie_search_datatype/_doc/1 37 | { 38 | "showRange": { 39 | "gte": "2001-01-01", 40 | "lte": "2001-12-31" 41 | } 42 | } 43 | 44 | # 결과 45 | { 46 | "_index": "movie_search_datatype", 47 | "_type": "_doc", 48 | "_id": "1", 49 | "_version": 1, 50 | "result": "created", 51 | "_shards": { 52 | "total": 2, 53 | "successful": 1, 54 | "failed": 0 55 | }, 56 | "_seq_no": 0, 57 | "_primary_term": 1 58 | } 59 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/07.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_datatype 3 | {} 4 | 5 | # 결과 6 | { 7 | "acknowledged": true, 8 | "shards_acknowledged": true, 9 | "index": "movie_search_datatype" 10 | } 11 | 12 | 13 | 14 | 15 | 16 | # 요청 17 | PUT movie_search_datatype/_mapping/_doc 18 | { 19 | "properties": { 20 | "check": { 21 | "type": "boolean" 22 | } 23 | } 24 | } 25 | 26 | # 결과 27 | { 28 | "acknowledged": true 29 | } 30 | 31 | 32 | 33 | 34 | 35 | 36 | # 요청 37 | PUT movie_search_datatype/_doc/1 38 | { 39 | "check": true 40 | } 41 | 42 | # 결과 43 | { 44 | "_index": "movie_search_datatype", 45 | "_type": "_doc", 46 | "_id": "1", 47 | "_version": 1, 48 | "result": "created", 49 | "_shards": { 50 | "total": 2, 51 | "successful": 1, 52 | "failed": 0 53 | }, 54 | "_seq_no": 0, 55 | "_primary_term": 1 56 | } 57 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/08.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_datatype 3 | {} 4 | 5 | # 결과 6 | { 7 | "acknowledged": true, 8 | "shards_acknowledged": true, 9 | "index": "movie_search_datatype" 10 | } 11 | 12 | 13 | 14 | 15 | 16 | 17 | # 요청 18 | PUT movie_search_datatype/_mapping/_doc 19 | { 20 | "properties": { 21 | "filmLocation": { 22 | "type": "geo_point" 23 | } 24 | } 25 | } 26 | 27 | # 결과 28 | { 29 | "acknowledged": true 30 | } 31 | 32 | 33 | 34 | 35 | 36 | 37 | # 요청 38 | PUT movie_search_datatype/_doc/1 39 | { 40 | "title" : "해리포터와 마법사의 돌", 41 | "filmLocation": { 42 | "lat" : 55.4155828, 43 | "lon" : -1.7081091 44 | } 45 | } 46 | 47 | # 결과 48 | { 49 | "_index": "movie_search_datatype", 50 | "_type": "_doc", 51 | "_id": "1", 52 | "_version": 1, 53 | "result": "created", 54 | "_shards": { 55 | "total": 2, 56 | "successful": 1, 57 | "failed": 0 58 | }, 59 | "_seq_no": 0, 60 | "_primary_term": 1 61 | } 62 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/09.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_datatype 3 | {} 4 | 5 | # 결과 6 | { 7 | "acknowledged": true, 8 | "shards_acknowledged": true, 9 | "index": "movie_search_datatype" 10 | } 11 | 12 | 13 | 14 | 15 | 16 | 17 | # 요청 18 | PUT movie_search_datatype/_mapping/_doc 19 | { 20 | "properties": { 21 | "ipAddr": { 22 | "type": "ip" 23 | } 24 | } 25 | } 26 | 27 | # 결과 28 | { 29 | "acknowledged": true 30 | } 31 | 32 | 33 | 34 | 35 | 36 | 37 | # 요청 38 | PUT movie_search_datatype/_doc/1 39 | { 40 | "ipAddr" : "127.0.0.1" 41 | } 42 | 43 | # 결과 44 | { 45 | "_index": "movie_search_datatype", 46 | "_type": "_doc", 47 | "_id": "1", 48 | "_version": 1, 49 | "result": "created", 50 | "_shards": { 51 | "total": 2, 52 | "successful": 1, 53 | "failed": 0 54 | }, 55 | "_seq_no": 0, 56 | "_primary_term": 1 57 | } 58 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.3/10.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_search_datatype 3 | {} 4 | 5 | # 결과 6 | { 7 | "acknowledged": true, 8 | "shards_acknowledged": true, 9 | "index": "movie_search_datatype" 10 | } 11 | 12 | 13 | 14 | 15 | 16 | 17 | # 요청 18 | PUT movie_search_datatype/_mapping/_doc 19 | { 20 | "properties": { 21 | "companies": { 22 | "properties": { 23 | "companyName": { 24 | "type": "text" 25 | } 26 | } 27 | } 28 | } 29 | } 30 | 31 | # 결과 32 | { 33 | "acknowledged": true 34 | } 35 | 36 | 37 | 38 | 39 | 40 | 41 | # 요청 42 | PUT movie_search_datatype/_doc/1 43 | { 44 | "title": "해리포터와 마법사의 돌", 45 | "companies": { 46 | "companyName": "워너브라더스" 47 | } 48 | } 49 | 50 | # 결과 51 | { 52 | "_index": "movie_search_datatype", 53 | "_type": "_doc", 54 | "_id": "1", 55 | "_version": 1, 56 | "result": "created", 57 | "_shards": { 58 | "total": 2, 59 | "successful": 1, 60 | "failed": 0 61 | }, 62 | "_seq_no": 0, 63 | "_primary_term": 1 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/01.txt: -------------------------------------------------------------------------------- 1 | 다음과 같은 문서를 분석한다면 2 | ---------------------------------------------------- 3 | "우리나라가 좋은나라, 대한민국 화이팅" 4 | ---------------------------------------------------- 5 | 6 | 7 | 8 | 9 | # 요청 10 | POST _analyze 11 | { 12 | "analyzer" : "standard", 13 | "text" : "우리나라가 좋은나라, 대한민국 화이팅" 14 | } 15 | 16 | # 결과 17 | { 18 | "tokens" : [ 19 | { 20 | "token" : "우리나라가", 21 | "start_offset" : 0, 22 | "end_offset" : 5, 23 | "type" : "", 24 | "position" : 0 25 | }, 26 | { 27 | "token" : "좋은나라", 28 | "start_offset" : 6, 29 | "end_offset" : 10, 30 | "type" : "", 31 | "position" : 1 32 | }, 33 | { 34 | "token" : "대한민국", 35 | "start_offset" : 12, 36 | "end_offset" : 16, 37 | "type" : "", 38 | "position" : 2 39 | }, 40 | { 41 | "token" : "화이팅", 42 | "start_offset" : 17, 43 | "end_offset" : 20, 44 | "type" : "", 45 | "position" : 3 46 | } 47 | ] 48 | } 49 | 50 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/02.txt: -------------------------------------------------------------------------------- 1 | 다음과 같은 문서를 분석한다면 2 | ---------------------------------------------------- 3 | Elasticsearch is cool 4 | ---------------------------------------------------- 5 | 6 | 7 | 8 | 9 | # 요청 10 | PUT movie_analyzer 11 | { 12 | "settings":{ 13 | "index": { 14 | "number_of_shards": 5, 15 | "number_of_replicas": 1 16 | }, 17 | "analysis":{ 18 | "analyzer":{ 19 | "movie_lower_test_analyzer":{ 20 | "type":"custom", 21 | "tokenizer":"standard", 22 | "filter":[ 23 | "lowercase" 24 | ] 25 | }, 26 | "movie_stop_test_analyzer":{ 27 | "type":"custom", 28 | "tokenizer":"standard", 29 | "filter":[ 30 | "lowercase", 31 | "english_stop" 32 | ] 33 | } 34 | }, 35 | "filter":{ 36 | "english_stop":{ 37 | "type":"stop", 38 | "stopwords":"_english_" 39 | } 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST _analyze 3 | { 4 | "analyzer": "standard", 5 | "text": "캐리비안의 해적 " 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens": [ 11 | { 12 | "token": "캐리비안의", 13 | "start_offset": 0, 14 | "end_offset": 5, 15 | "type": "", 16 | "position": 0 17 | }, 18 | { 19 | "token": "해적", 20 | "start_offset": 6, 21 | "end_offset": 8, 22 | "type": "", 23 | "position": 1 24 | } 25 | ] 26 | } 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | # 요청 35 | POST movie_analyzer/_analyze 36 | { 37 | "analyzer": "standard", 38 | "text": "캐리비안의 해적 " 39 | } 40 | 41 | # 결과 42 | { 43 | "tokens": [ 44 | { 45 | "token": "캐리비안의", 46 | "start_offset": 0, 47 | "end_offset": 5, 48 | "type": "", 49 | "position": 0 50 | }, 51 | { 52 | "token": "해적", 53 | "start_offset": 6, 54 | "end_offset": 8, 55 | "type": "", 56 | "position": 1 57 | } 58 | ] 59 | } 60 | 61 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST _analyze 3 | { 4 | "analyzer": "standard", 5 | "text": "Harry Potter and the Chamber of Secrets" 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens" : [ 11 | { 12 | "token" : "harry", 13 | "start_offset" : 0, 14 | "end_offset" : 5, 15 | "type" : "", 16 | "position" : 0 17 | }, 18 | { 19 | "token" : "potter", 20 | "start_offset" : 6, 21 | "end_offset" : 12, 22 | "type" : "", 23 | "position" : 1 24 | }, 25 | { 26 | "token" : "and", 27 | "start_offset" : 13, 28 | "end_offset" : 16, 29 | "type" : "", 30 | "position" : 2 31 | }, 32 | { 33 | "token" : "the", 34 | "start_offset" : 17, 35 | "end_offset" : 20, 36 | "type" : "", 37 | "position" : 3 38 | }, 39 | { 40 | "token" : "chamber", 41 | "start_offset" : 21, 42 | "end_offset" : 28, 43 | "type" : "", 44 | "position" : 4 45 | }, 46 | { 47 | "token" : "of", 48 | "start_offset" : 29, 49 | "end_offset" : 31, 50 | "type" : "", 51 | "position" : 5 52 | }, 53 | { 54 | "token" : "secrets", 55 | "start_offset" : 32, 56 | "end_offset" : 39, 57 | "type" : "", 58 | "position" : 6 59 | } 60 | ] 61 | } 62 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_analyzer/_doc/1 3 | { 4 | "title": "Harry Potter and the Chamber of Secrets" 5 | } 6 | 7 | 8 | 9 | 10 | 11 | 12 | # 요청 13 | POST movie_analyzer/_analyze 14 | { 15 | "field": "title", 16 | "text": "Harry Potter and the Chamber of Secrets" 17 | } 18 | 19 | # 결과 20 | { 21 | "tokens" : [ 22 | { 23 | "token" : "harry", 24 | "start_offset" : 0, 25 | "end_offset" : 5, 26 | "type" : "", 27 | "position" : 0 28 | }, 29 | { 30 | "token" : "potter", 31 | "start_offset" : 6, 32 | "end_offset" : 12, 33 | "type" : "", 34 | "position" : 1 35 | }, 36 | { 37 | "token" : "and", 38 | "start_offset" : 13, 39 | "end_offset" : 16, 40 | "type" : "", 41 | "position" : 2 42 | }, 43 | { 44 | "token" : "the", 45 | "start_offset" : 17, 46 | "end_offset" : 20, 47 | "type" : "", 48 | "position" : 3 49 | }, 50 | { 51 | "token" : "chamber", 52 | "start_offset" : 21, 53 | "end_offset" : 28, 54 | "type" : "", 55 | "position" : 4 56 | }, 57 | { 58 | "token" : "of", 59 | "start_offset" : 29, 60 | "end_offset" : 31, 61 | "type" : "", 62 | "position" : 5 63 | }, 64 | { 65 | "token" : "secrets", 66 | "start_offset" : 32, 67 | "end_offset" : 39, 68 | "type" : "", 69 | "position" : 6 70 | } 71 | ] 72 | } 73 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/06.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_analyzer 3 | { 4 | "settings":{ 5 | "index": { 6 | "number_of_shards": 5, 7 | "number_of_replicas": 1 8 | }, 9 | "analysis":{ 10 | "analyzer":{ 11 | "movie_lower_test_analyzer":{ 12 | "type":"custom", 13 | "tokenizer":"standard", 14 | "filter":[ 15 | "lowercase" 16 | ] 17 | }, 18 | "movie_stop_test_analyzer":{ 19 | "type":"custom", 20 | "tokenizer":"standard", 21 | "filter":[ 22 | "lowercase", 23 | "english_stop" 24 | ] 25 | } 26 | }, 27 | "filter":{ 28 | "english_stop":{ 29 | "type":"stop", 30 | "stopwords":"_english_" 31 | } 32 | } 33 | } 34 | }, 35 | "mappings":{ 36 | "_doc":{ 37 | "properties":{ 38 | "title": { 39 | "type":"text", 40 | "analyzer":"movie_lower_test_analyzer", 41 | "search_analyzer":"movie_stop_test_analyzer" 42 | } 43 | } 44 | } 45 | } 46 | } 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | # 요청 55 | PUT movie_analyzer/_doc/1 56 | { 57 | "title": "Harry Potter and the Chamber of Secrets" 58 | } 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | # 요청 67 | POST movie_analyzer/_search 68 | { 69 | "query": { 70 | "query_string": { 71 | "default_operator": "AND", 72 | "query": "Chamber of Secrets" 73 | } 74 | } 75 | } 76 | 77 | # 결과 78 | { 79 | "took": 1, 80 | "timed_out": false, 81 | "_shards": { 82 | "total": 5, 83 | "successful": 5, 84 | "skipped": 0, 85 | "failed": 0 86 | }, 87 | "hits": { 88 | "total": 1, 89 | "max_score": 0.5753642, 90 | "hits": [ 91 | { 92 | "_index": "movie_analyzer", 93 | "_type": "_doc", 94 | "_id": "1", 95 | "_score": 0.5753642, 96 | "_source": { 97 | "title": "Harry Potter and the Chamber of Secrets" 98 | } 99 | } 100 | ] 101 | } 102 | } 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/07.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_analyzer/_analyze 3 | { 4 | "analyzer": "standard", 5 | "text": "Harry Potter and the Chamber of Secrets" 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens" : [ 11 | { 12 | "token" : "harry", 13 | "start_offset" : 0, 14 | "end_offset" : 5, 15 | "type" : "", 16 | "position" : 0 17 | }, 18 | { 19 | "token" : "potter", 20 | "start_offset" : 6, 21 | "end_offset" : 12, 22 | "type" : "", 23 | "position" : 1 24 | }, 25 | { 26 | "token" : "and", 27 | "start_offset" : 13, 28 | "end_offset" : 16, 29 | "type" : "", 30 | "position" : 2 31 | }, 32 | { 33 | "token" : "the", 34 | "start_offset" : 17, 35 | "end_offset" : 20, 36 | "type" : "", 37 | "position" : 3 38 | }, 39 | { 40 | "token" : "chamber", 41 | "start_offset" : 21, 42 | "end_offset" : 28, 43 | "type" : "", 44 | "position" : 4 45 | }, 46 | { 47 | "token" : "of", 48 | "start_offset" : 29, 49 | "end_offset" : 31, 50 | "type" : "", 51 | "position" : 5 52 | }, 53 | { 54 | "token" : "secrets", 55 | "start_offset" : 32, 56 | "end_offset" : 39, 57 | "type" : "", 58 | "position" : 6 59 | } 60 | ] 61 | } 62 | 63 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/08.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_analyzer/_analyze 3 | { 4 | "analyzer": "whitespace", 5 | "text": "Harry Potter and the Chamber of Secrets" 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens" : [ 11 | { 12 | "token" : "Harry", 13 | "start_offset" : 0, 14 | "end_offset" : 5, 15 | "type" : "word", 16 | "position" : 0 17 | }, 18 | { 19 | "token" : "Potter", 20 | "start_offset" : 6, 21 | "end_offset" : 12, 22 | "type" : "word", 23 | "position" : 1 24 | }, 25 | { 26 | "token" : "and", 27 | "start_offset" : 13, 28 | "end_offset" : 16, 29 | "type" : "word", 30 | "position" : 2 31 | }, 32 | { 33 | "token" : "the", 34 | "start_offset" : 17, 35 | "end_offset" : 20, 36 | "type" : "word", 37 | "position" : 3 38 | }, 39 | { 40 | "token" : "Chamber", 41 | "start_offset" : 21, 42 | "end_offset" : 28, 43 | "type" : "word", 44 | "position" : 4 45 | }, 46 | { 47 | "token" : "of", 48 | "start_offset" : 29, 49 | "end_offset" : 31, 50 | "type" : "word", 51 | "position" : 5 52 | }, 53 | { 54 | "token" : "Secrets", 55 | "start_offset" : 32, 56 | "end_offset" : 39, 57 | "type" : "word", 58 | "position" : 6 59 | } 60 | ] 61 | } 62 | 63 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/09.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_analyzer/_analyze 3 | { 4 | "analyzer": "keyword", 5 | "text": "Harry Potter and the Chamber of Secrets" 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens" : [ 11 | { 12 | "token" : "Harry Potter and the Chamber of Secrets", 13 | "start_offset" : 0, 14 | "end_offset" : 39, 15 | "type" : "word", 16 | "position" : 0 17 | } 18 | ] 19 | } 20 | 21 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/10.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_html_analyzer 3 | { 4 | "settings": { 5 | "analysis": { 6 | "analyzer": { 7 | "html_strip_analyzer": { 8 | "tokenizer": "keyword", 9 | "char_filter": [ 10 | "html_strip_char_filter" 11 | ] 12 | } 13 | }, 14 | "char_filter": { 15 | "html_strip_char_filter": { 16 | "type": "html_strip", 17 | "escaped_tags": [ 18 | "b" 19 | ] 20 | } 21 | } 22 | } 23 | } 24 | } 25 | 26 | # 결과 27 | { 28 | "acknowledged": true, 29 | "shards_acknowledged": true, 30 | "index": "movie_html_analyzer" 31 | } 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | # 요청 40 | POST movie_html_analyzer/_analyze 41 | { 42 | "analyzer": "html_strip_analyzer", 43 | "text": "Harry Potter and the Chamber of Secrets" 44 | } 45 | 46 | # 결과 47 | { 48 | "tokens": [ 49 | { 50 | "token": "Harry Potter and the Chamber of Secrets", 51 | "start_offset": 6, 52 | "end_offset": 59, 53 | "type": "word", 54 | "position": 0 55 | } 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/11.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_analyzer/_analyze 3 | { 4 | "tokenizer": "standard", 5 | "text": "Harry Potter and the Chamber of Secrets" 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens": [ 11 | { 12 | "token": "Harry", 13 | "start_offset": 0, 14 | "end_offset": 5, 15 | "type": "", 16 | "position": 0 17 | }, 18 | { 19 | "token": "Potter", 20 | "start_offset": 6, 21 | "end_offset": 12, 22 | "type": "", 23 | "position": 1 24 | }, 25 | { 26 | "token": "and", 27 | "start_offset": 13, 28 | "end_offset": 16, 29 | "type": "", 30 | "position": 2 31 | }, 32 | { 33 | "token": "the", 34 | "start_offset": 17, 35 | "end_offset": 20, 36 | "type": "", 37 | "position": 3 38 | }, 39 | { 40 | "token": "Chamber", 41 | "start_offset": 21, 42 | "end_offset": 28, 43 | "type": "", 44 | "position": 4 45 | }, 46 | { 47 | "token": "of", 48 | "start_offset": 29, 49 | "end_offset": 31, 50 | "type": "", 51 | "position": 5 52 | }, 53 | { 54 | "token": "Secrets", 55 | "start_offset": 32, 56 | "end_offset": 39, 57 | "type": "", 58 | "position": 6 59 | } 60 | ] 61 | } 62 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/12.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_analyzer/_analyze 3 | { 4 | "tokenizer": "whitespace", 5 | "text": "Harry Potter and the Chamber of Secrets" 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens": [ 11 | { 12 | "token": "Harry", 13 | "start_offset": 0, 14 | "end_offset": 5, 15 | "type": "word", 16 | "position": 0 17 | }, 18 | { 19 | "token": "Potter", 20 | "start_offset": 6, 21 | "end_offset": 12, 22 | "type": "word", 23 | "position": 1 24 | }, 25 | { 26 | "token": "and", 27 | "start_offset": 13, 28 | "end_offset": 16, 29 | "type": "word", 30 | "position": 2 31 | }, 32 | { 33 | "token": "the", 34 | "start_offset": 17, 35 | "end_offset": 20, 36 | "type": "word", 37 | "position": 3 38 | }, 39 | { 40 | "token": "Chamber", 41 | "start_offset": 21, 42 | "end_offset": 28, 43 | "type": "word", 44 | "position": 4 45 | }, 46 | { 47 | "token": "of", 48 | "start_offset": 29, 49 | "end_offset": 31, 50 | "type": "word", 51 | "position": 5 52 | }, 53 | { 54 | "token": "Secrets", 55 | "start_offset": 32, 56 | "end_offset": 39, 57 | "type": "word", 58 | "position": 6 59 | } 60 | ] 61 | } 62 | 63 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/15.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_analyzer/_analyze 3 | { 4 | "tokenizer": "keyword", 5 | "text": "Harry Potter and the Chamber of Secrets" 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens": [ 11 | { 12 | "token": "Harry Potter and the Chamber of Secrets", 13 | "start_offset": 0, 14 | "end_offset": 39, 15 | "type": "word", 16 | "position": 0 17 | } 18 | ] 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/16.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_af_analyzer 3 | { 4 | "settings": { 5 | "analysis": { 6 | "analyzer": { 7 | "asciifolding_analyzer": { 8 | "tokenizer": "standard", 9 | "filter": [ 10 | "standard", 11 | "asciifolding" 12 | ] 13 | } 14 | } 15 | } 16 | } 17 | } 18 | 19 | # 결과 20 | { 21 | "acknowledged": true, 22 | "shards_acknowledged": true, 23 | "index": "movie_af_analyzer" 24 | } 25 | 26 | 27 | 28 | 29 | 30 | 31 | # 요청 32 | POST movie_af_analyzer/_analyze 33 | { 34 | "analyzer": "asciifolding_analyzer", 35 | "text": "hello javacáfe" 36 | } 37 | 38 | # 결과 39 | { 40 | "tokens": [ 41 | { 42 | "token": "hello", 43 | "start_offset": 0, 44 | "end_offset": 5, 45 | "type": "", 46 | "position": 0 47 | }, 48 | { 49 | "token": "javacafe", 50 | "start_offset": 6, 51 | "end_offset": 14, 52 | "type": "", 53 | "position": 1 54 | } 55 | ] 56 | } 57 | 58 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/17.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_lower_analyzer 3 | { 4 | "settings": { 5 | "analysis": { 6 | "analyzer": { 7 | "lowercase_analyzer": { 8 | "tokenizer": "standard", 9 | "filter": [ 10 | "lowercase" 11 | ] 12 | } 13 | } 14 | } 15 | } 16 | } 17 | 18 | # 결과 19 | { 20 | "acknowledged": true, 21 | "shards_acknowledged": true, 22 | "index": "movie_lower_analyzer" 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | # 요청 31 | POST movie_lower_analyzer/_analyze 32 | { 33 | "analyzer": "lowercase_analyzer", 34 | "text": "Harry Potter and the Chamber of Secrets" 35 | } 36 | 37 | # 결과 38 | { 39 | "tokens": [ 40 | { 41 | "token": "harry", 42 | "start_offset": 0, 43 | "end_offset": 5, 44 | "type": "", 45 | "position": 0 46 | }, 47 | { 48 | "token": "potter", 49 | "start_offset": 6, 50 | "end_offset": 12, 51 | "type": "", 52 | "position": 1 53 | }, 54 | { 55 | "token": "and", 56 | "start_offset": 13, 57 | "end_offset": 16, 58 | "type": "", 59 | "position": 2 60 | }, 61 | { 62 | "token": "the", 63 | "start_offset": 17, 64 | "end_offset": 20, 65 | "type": "", 66 | "position": 3 67 | }, 68 | { 69 | "token": "chamber", 70 | "start_offset": 21, 71 | "end_offset": 28, 72 | "type": "", 73 | "position": 4 74 | }, 75 | { 76 | "token": "of", 77 | "start_offset": 29, 78 | "end_offset": 31, 79 | "type": "", 80 | "position": 5 81 | }, 82 | { 83 | "token": "secrets", 84 | "start_offset": 32, 85 | "end_offset": 39, 86 | "type": "", 87 | "position": 6 88 | } 89 | ] 90 | } 91 | 92 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/18.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_upper_analyzer 3 | { 4 | "settings": { 5 | "analysis": { 6 | "analyzer": { 7 | "uppercase_analyzer": { 8 | "tokenizer": "standard", 9 | "filter": [ 10 | "uppercase" 11 | ] 12 | } 13 | } 14 | } 15 | } 16 | } 17 | 18 | # 결과 19 | { 20 | "acknowledged": true, 21 | "shards_acknowledged": true, 22 | "index": "movie_upper_analyzer" 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | # 요청 31 | POST movie_upper_analyzer/_analyze 32 | { 33 | "analyzer": "uppercase_analyzer", 34 | "text": "Harry Potter and the Chamber of Secrets" 35 | } 36 | 37 | # 결과 38 | { 39 | "tokens": [ 40 | { 41 | "token": "HARRY", 42 | "start_offset": 0, 43 | "end_offset": 5, 44 | "type": "", 45 | "position": 0 46 | }, 47 | { 48 | "token": "POTTER", 49 | "start_offset": 6, 50 | "end_offset": 12, 51 | "type": "", 52 | "position": 1 53 | }, 54 | { 55 | "token": "AND", 56 | "start_offset": 13, 57 | "end_offset": 16, 58 | "type": "", 59 | "position": 2 60 | }, 61 | { 62 | "token": "THE", 63 | "start_offset": 17, 64 | "end_offset": 20, 65 | "type": "", 66 | "position": 3 67 | }, 68 | { 69 | "token": "CHAMBER", 70 | "start_offset": 21, 71 | "end_offset": 28, 72 | "type": "", 73 | "position": 4 74 | }, 75 | { 76 | "token": "OF", 77 | "start_offset": 29, 78 | "end_offset": 31, 79 | "type": "", 80 | "position": 5 81 | }, 82 | { 83 | "token": "SECRETS", 84 | "start_offset": 32, 85 | "end_offset": 39, 86 | "type": "", 87 | "position": 6 88 | } 89 | ] 90 | } 91 | 92 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/19.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_stop_analyzer 3 | { 4 | "settings": { 5 | "analysis": { 6 | "analyzer": { 7 | "stop_filter_analyzer": { 8 | "tokenizer": "standard", 9 | "filter": [ 10 | "standard", 11 | "stop_filter" 12 | ] 13 | } 14 | }, 15 | "filter": { 16 | "stop_filter": { 17 | "type": "stop", 18 | "stopwords": [ 19 | "and", 20 | "is", 21 | "the" 22 | ] 23 | } 24 | } 25 | } 26 | } 27 | } 28 | 29 | # 결과 30 | { 31 | "acknowledged": true, 32 | "shards_acknowledged": true, 33 | "index": "movie_stop_analyzer" 34 | } 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | # 요청 43 | POST movie_stop_analyzer/_analyze 44 | { 45 | "analyzer": "stop_filter_analyzer", 46 | "text": "Harry Potter and the Chamber of Secrets" 47 | } 48 | 49 | # 결과 50 | { 51 | "tokens": [ 52 | { 53 | "token": "Harry", 54 | "start_offset": 0, 55 | "end_offset": 5, 56 | "type": "", 57 | "position": 0 58 | }, 59 | { 60 | "token": "Potter", 61 | "start_offset": 6, 62 | "end_offset": 12, 63 | "type": "", 64 | "position": 1 65 | }, 66 | { 67 | "token": "Chamber", 68 | "start_offset": 21, 69 | "end_offset": 28, 70 | "type": "", 71 | "position": 4 72 | }, 73 | { 74 | "token": "of", 75 | "start_offset": 29, 76 | "end_offset": 31, 77 | "type": "", 78 | "position": 5 79 | }, 80 | { 81 | "token": "Secrets", 82 | "start_offset": 32, 83 | "end_offset": 39, 84 | "type": "", 85 | "position": 6 86 | } 87 | ] 88 | } 89 | 90 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/20.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_stem_analyzer 3 | { 4 | "settings": { 5 | "analysis": { 6 | "analyzer": { 7 | "stemmer_eng_analyzer": { 8 | "tokenizer": "standard", 9 | "filter": [ 10 | "standard", 11 | "lowercase", 12 | "stemmer_eng_filter" 13 | ] 14 | } 15 | }, 16 | "filter": { 17 | "stemmer_eng_filter": { 18 | "type": "stemmer", 19 | "name": "english" 20 | } 21 | } 22 | } 23 | } 24 | } 25 | 26 | # 결과 27 | { 28 | "acknowledged": true, 29 | "shards_acknowledged": true, 30 | "index": "movie_stem_analyzer" 31 | } 32 | 33 | 34 | 35 | 36 | 37 | 38 | # 요청 39 | POST movie_stem_analyzer/_analyze 40 | { 41 | "analyzer": "stemmer_eng_analyzer", 42 | "text": "Harry Potter and the Chamber of Secrets" 43 | } 44 | 45 | # 결과 46 | { 47 | "tokens": [ 48 | { 49 | "token": "harri", 50 | "start_offset": 0, 51 | "end_offset": 5, 52 | "type": "", 53 | "position": 0 54 | }, 55 | { 56 | "token": "potter", 57 | "start_offset": 6, 58 | "end_offset": 12, 59 | "type": "", 60 | "position": 1 61 | }, 62 | { 63 | "token": "and", 64 | "start_offset": 13, 65 | "end_offset": 16, 66 | "type": "", 67 | "position": 2 68 | }, 69 | { 70 | "token": "the", 71 | "start_offset": 17, 72 | "end_offset": 20, 73 | "type": "", 74 | "position": 3 75 | }, 76 | { 77 | "token": "chamber", 78 | "start_offset": 21, 79 | "end_offset": 28, 80 | "type": "", 81 | "position": 4 82 | }, 83 | { 84 | "token": "of", 85 | "start_offset": 29, 86 | "end_offset": 31, 87 | "type": "", 88 | "position": 5 89 | }, 90 | { 91 | "token": "secret", 92 | "start_offset": 32, 93 | "end_offset": 39, 94 | "type": "", 95 | "position": 6 96 | } 97 | ] 98 | } 99 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/21.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_syno_analyzer 3 | { 4 | "settings": { 5 | "analysis": { 6 | "analyzer": { 7 | "synonym_analyzer": { 8 | "tokenizer": "whitespace", 9 | "filter": [ 10 | "synonym_filter" 11 | ] 12 | } 13 | }, 14 | "filter": { 15 | "synonym_filter": { 16 | "type": "synonym", 17 | "synonyms": [ 18 | "Harry => 해리" 19 | ] 20 | } 21 | } 22 | } 23 | } 24 | } 25 | 26 | # 결과 27 | { 28 | "acknowledged": true, 29 | "shards_acknowledged": true, 30 | "index": "movie_syno_analyzer" 31 | } 32 | 33 | 34 | 35 | 36 | 37 | 38 | # 요청 39 | POST movie_syno_analyzer/_analyze 40 | { 41 | "analyzer": "synonym_analyzer", 42 | "text": "Harry Potter and the Chamber of Secrets" 43 | } 44 | 45 | # 결과 46 | { 47 | "tokens": [ 48 | { 49 | "token": "해리", 50 | "start_offset": 0, 51 | "end_offset": 5, 52 | "type": "SYNONYM", 53 | "position": 0 54 | }, 55 | { 56 | "token": "Potter", 57 | "start_offset": 6, 58 | "end_offset": 12, 59 | "type": "word", 60 | "position": 1 61 | }, 62 | { 63 | "token": "and", 64 | "start_offset": 13, 65 | "end_offset": 16, 66 | "type": "word", 67 | "position": 2 68 | }, 69 | { 70 | "token": "the", 71 | "start_offset": 17, 72 | "end_offset": 20, 73 | "type": "word", 74 | "position": 3 75 | }, 76 | { 77 | "token": "Chamber", 78 | "start_offset": 21, 79 | "end_offset": 28, 80 | "type": "word", 81 | "position": 4 82 | }, 83 | { 84 | "token": "of", 85 | "start_offset": 29, 86 | "end_offset": 31, 87 | "type": "word", 88 | "position": 5 89 | }, 90 | { 91 | "token": "Secrets", 92 | "start_offset": 32, 93 | "end_offset": 39, 94 | "type": "word", 95 | "position": 6 96 | } 97 | ] 98 | } 99 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/22.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_trim_analyzer 3 | { 4 | "settings": { 5 | "analysis": { 6 | "analyzer": { 7 | "trim_analyzer": { 8 | "tokenizer": "keyword", 9 | "filter": [ 10 | "lowercase", 11 | "trim" 12 | ] 13 | } 14 | } 15 | } 16 | } 17 | } 18 | 19 | # 결과 20 | { 21 | "acknowledged": true, 22 | "shards_acknowledged": true, 23 | "index": "movie_trim_analyzer" 24 | } 25 | 26 | 27 | 28 | 29 | 30 | 31 | # 요청 32 | POST movie_trim_analyzer/_analyze 33 | { 34 | "analyzer": "trim_analyzer", 35 | "text": " Harry Potter and the Chamber of Secrets " 36 | } 37 | 38 | # 결과 39 | { 40 | "tokens": [ 41 | { 42 | "token": "harry potter and the chamber of secrets", 43 | "start_offset": 0, 44 | "end_offset": 47, 45 | "type": "word", 46 | "position": 0 47 | } 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.4/synonym.txt: -------------------------------------------------------------------------------- 1 | Elasticsearch, 엘라스틱서치 2 | Harry => 해리 3 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/01.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST moive_dynamic/_doc 3 | { 4 | "movieCd": "20173732", 5 | "movieNm": "살아남은 아이", 6 | "movieNmEn": "Last Child", 7 | "typeNm": "장편" 8 | } 9 | 10 | # 결과 11 | { 12 | "_index": "moive_dynamic", 13 | "_type": "_doc", 14 | "_id": "KKHqG2oBUivRX-_RRxM-", 15 | "_version": 1, 16 | "result": "created", 17 | "_shards": { 18 | "total": 2, 19 | "successful": 1, 20 | "failed": 0 21 | }, 22 | "_seq_no": 0, 23 | "_primary_term": 1 24 | } 25 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_dynamic/_doc/1 3 | { 4 | "nationAlt": "한국" 5 | } 6 | 7 | # 결과 8 | { 9 | "_index": "moive_dynamic", 10 | "_type": "_doc", 11 | "_id": "1", 12 | "_version": 1, 13 | "result": "created", 14 | "_shards": { 15 | "total": 2, 16 | "successful": 1, 17 | "failed": 0 18 | }, 19 | "_seq_no": 0, 20 | "_primary_term": 1 21 | } 22 | 23 | 24 | 25 | 26 | 27 | 28 | # 요청 29 | PUT movie_dynamic/_doc/1 30 | { 31 | "nationAlt": "한국" 32 | } 33 | 34 | # 결과 35 | { 36 | "_index": "moive_dynamic", 37 | "_type": "_doc", 38 | "_id": "1", 39 | "_version": 2, 40 | "result": "updated", 41 | "_shards": { 42 | "total": 2, 43 | "successful": 1, 44 | "failed": 0 45 | }, 46 | "_seq_no": 1, 47 | "_primary_term": 1 48 | } 49 | 50 | 51 | 52 | 53 | 54 | 55 | # 요청 56 | PUT movie_dynamic/_doc/1?version=2 57 | { 58 | "nationAlt": "한국" 59 | } 60 | 61 | # 결과 62 | { 63 | "error": { 64 | "root_cause": [ 65 | { 66 | "type": "version_conflict_engine_exception", 67 | "reason": "[_doc][1]: version conflict, current version [2] is different than the one provided [1]", 68 | "index_uuid": "_T4-KkSvQQ6r0Ui5I238Rw", 69 | "shard": "3", 70 | "index": "moive_dynamic" 71 | } 72 | ], 73 | "type": "version_conflict_engine_exception", 74 | "reason": "[_doc][1]: version conflict, current version [2] is different than the one provided [1]", 75 | "index_uuid": "_T4-KkSvQQ6r0Ui5I238Rw", 76 | "shard": "3", 77 | "index": "moive_dynamic" 78 | }, 79 | "status": 409 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_dynamic/_doc/1?op_type=create 3 | { 4 | "movieCd": "20173732", 5 | "movieNm": "살아남은 아이", 6 | "movieNmEn": "Last Child", 7 | "typeNm": "단편" 8 | } 9 | 10 | # 결과 11 | { 12 | "_index" : "movie_dynamic", 13 | "_type" : "_doc", 14 | "_id" : "1", 15 | "_version" : 1, 16 | "result" : "created", 17 | "_shards" : { 18 | "total" : 2, 19 | "successful" : 1, 20 | "failed" : 0 21 | }, 22 | "_seq_no" : 0, 23 | "_primary_term" : 1 24 | } 25 | 26 | 27 | 28 | 29 | 30 | 31 | # 요청 32 | PUT movie_dynamic/_doc/1?op_type=create 33 | { 34 | "movieCd": "20173732", 35 | "movieNm": "살아남은 아이", 36 | "movieNmEn": "Last Child", 37 | "typeNm": "단편" 38 | } 39 | 40 | # 결과 41 | { 42 | "error": { 43 | "root_cause": [ 44 | { 45 | "type": "version_conflict_engine_exception", 46 | "reason": "[_doc][1]: version conflict, document already exists (current version [1])", 47 | "index_uuid": "FBnpPpSlQSCj0QJUW8eF-Q", 48 | "shard": "3", 49 | "index": "movie_dynamic" 50 | } 51 | ], 52 | "type": "version_conflict_engine_exception", 53 | "reason": "[_doc][1]: version conflict, document already exists (current version [1])", 54 | "index_uuid": "FBnpPpSlQSCj0QJUW8eF-Q", 55 | "shard": "3", 56 | "index": "movie_dynamic" 57 | }, 58 | "status": 409 59 | } -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_dynamic/_doc/1?timeout=5m 3 | { 4 | "movieCd": "20173732", 5 | "movieNm": "살아남은 아이", 6 | "movieNmEn": "Last Child", 7 | "typeNm": "장편" 8 | } 9 | 10 | # 결과 11 | { 12 | "_index" : "movie_dynamic", 13 | "_type" : "_doc", 14 | "_id" : "1", 15 | "_version" : 2, 16 | "result" : "updated", 17 | "_shards" : { 18 | "total" : 2, 19 | "successful" : 1, 20 | "failed" : 0 21 | }, 22 | "_seq_no" : 1, 23 | "_primary_term" : 1 24 | } 25 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_dynamic/_doc/1 3 | { 4 | "movieCd": "20173732", 5 | "movieNm": "살아남은 아이", 6 | "movieNmEn": "Last Child", 7 | "typeNm": "장편" 8 | } 9 | 10 | # 결과 11 | { 12 | "_index": "movie_dynamic", 13 | "_type": "_doc", 14 | "_id": "1", 15 | "_version": 1, 16 | "result": "created", 17 | "_shards": { 18 | "total": 2, 19 | "successful": 1, 20 | "failed": 0 21 | }, 22 | "_seq_no": 0, 23 | "_primary_term": 1 24 | } 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/06.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_dynamic 3 | { 4 | "mappings": { 5 | "_doc": { 6 | "properties": { 7 | "movieCd": { 8 | "type": "text", 9 | "store": true 10 | }, 11 | "movieNm": { 12 | "type": "text", 13 | "store": true 14 | }, 15 | "movieNmEn": { 16 | "type": "text" 17 | } 18 | } 19 | } 20 | } 21 | } 22 | 23 | # 결과 24 | { 25 | "acknowledged": true, 26 | "shards_acknowledged": true, 27 | "index": "movie_dynamic" 28 | } 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | # 요청 37 | PUT movie_dynamic/_doc/1 38 | { 39 | "movieCd": "20173732", 40 | "movieNm": "살아남은 아이", 41 | "movieNmEn": "Last Child" 42 | } 43 | 44 | # 결과 45 | { 46 | "_index" : "movie_dynamic", 47 | "_type" : "_doc", 48 | "_id" : "1", 49 | "_version" : 1, 50 | "result" : "created", 51 | "_shards" : { 52 | "total" : 2, 53 | "successful" : 1, 54 | "failed" : 0 55 | }, 56 | "_seq_no" : 0, 57 | "_primary_term" : 1 58 | } 59 | 60 | 61 | 62 | 63 | 64 | # 요청 65 | GET movie_dynamic/_doc/1 66 | 67 | # 결과 68 | { 69 | "_index": "movie_dynamic", 70 | "_type": "_doc", 71 | "_id": "1", 72 | "_version": 1, 73 | "found": true, 74 | "_source": { 75 | "movieCd": "20173732", 76 | "movieNm": "살아남은 아이", 77 | "movieNmEn": "Last Child" 78 | } 79 | } 80 | 81 | 82 | 83 | 84 | 85 | 86 | # 요청 87 | GET movie_dynamic/_doc/1?_source_exclude=movieNm 88 | 89 | # 결과 90 | { 91 | "_index": "movie_dynamic", 92 | "_type": "_doc", 93 | "_id": "1", 94 | "_version": 1, 95 | "found": true, 96 | "_source": { 97 | "movieCd": "20173732", 98 | "movieNmEn": "Last Child" 99 | } 100 | } 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/07.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | DELETE movie_dynamic/_doc/1 3 | 4 | # 결과 5 | { 6 | "_index" : "movie_dynamic", 7 | "_type" : "_doc", 8 | "_id" : "1", 9 | "_version" : 2, 10 | "result" : "deleted", 11 | "_shards" : { 12 | "total" : 2, 13 | "successful" : 1, 14 | "failed" : 0 15 | }, 16 | "_seq_no" : 1, 17 | "_primary_term" : 1 18 | } 19 | 20 | 21 | 22 | 23 | 24 | 25 | # 요청 26 | DELETE movie_dynamic 27 | 28 | # 결과 29 | { 30 | "acknowledged" : true 31 | } 32 | 33 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/08.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_dynamic/_doc/1 3 | { 4 | "movieCd": "20173732", 5 | "movieNm": "살아남은 아이", 6 | "movieNmEn": "Last Child" 7 | } 8 | 9 | # 결과 10 | { 11 | "_index": "movie_dynamic", 12 | "_type": "_doc", 13 | "_id": "1", 14 | "_version": 1, 15 | "result": "created", 16 | "_shards": { 17 | "total": 2, 18 | "successful": 1, 19 | "failed": 0 20 | }, 21 | "_seq_no": 0, 22 | "_primary_term": 1 23 | } 24 | 25 | 26 | 27 | 28 | 29 | 30 | # 요청 31 | POST movie_dynamic/_delete_by_query 32 | { 33 | "query": { 34 | "term": { 35 | "movieCd": "20173732" 36 | } 37 | } 38 | } 39 | 40 | # 결과 41 | { 42 | "took": 42, 43 | "timed_out": false, 44 | "total": 1, 45 | "deleted": 1, 46 | "batches": 1, 47 | "version_conflicts": 0, 48 | "noops": 0, 49 | "retries": { 50 | "bulk": 0, 51 | "search": 0 52 | }, 53 | "throttled_millis": 0, 54 | "requests_per_second": -1, 55 | "throttled_until_millis": 0, 56 | "failures": [] 57 | } 58 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/09.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_dynamic/_doc/1 3 | { 4 | "counter" : 1000, 5 | "movieNmEn" : "Last Child" 6 | } 7 | 8 | # 결과 9 | { 10 | "_index": "movie_dynamic", 11 | "_type": "_doc", 12 | "_id": "1", 13 | "_version": 1, 14 | "result": "created", 15 | "_shards": { 16 | "total": 2, 17 | "successful": 1, 18 | "failed": 0 19 | }, 20 | "_seq_no": 0, 21 | "_primary_term": 1 22 | } 23 | 24 | 25 | 26 | 27 | 28 | # 요청 29 | POST movie_dynamic/_doc/1/_update 30 | { 31 | "script" : { 32 | "source": "ctx._source.counter += params.count", 33 | "lang": "painless", 34 | "params" : { 35 | "count" : 1 36 | } 37 | } 38 | } 39 | 40 | # 결과 41 | { 42 | "_index": "movie_dynamic", 43 | "_type": "_doc", 44 | "_id": "1", 45 | "_version": 2, 46 | "result": "updated", 47 | "_shards": { 48 | "total": 2, 49 | "successful": 1, 50 | "failed": 0 51 | }, 52 | "_seq_no": 1, 53 | "_primary_term": 1 54 | } 55 | 56 | 57 | 58 | 59 | 60 | 61 | # 요청 62 | GET movie_dynamic/_doc/1 63 | 64 | # 결과 65 | { 66 | "_index": "movie_dynamic", 67 | "_type": "_doc", 68 | "_id": "1", 69 | "_version": 2, 70 | "found": true, 71 | "_source": { 72 | "counter": 1001, 73 | "movieNmEn": "Last Child" 74 | } 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/11.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST _reindex 3 | { 4 | "source": { 5 | "index": "movie_dynamic" 6 | }, 7 | "dest": { 8 | "index": "movie_dynamic_new", 9 | "version_type": "internal" 10 | } 11 | } 12 | 13 | # 결과 14 | { 15 | "took": 259, 16 | "timed_out": false, 17 | "total": 2, 18 | "updated": 0, 19 | "created": 2, 20 | "deleted": 0, 21 | "batches": 1, 22 | "version_conflicts": 0, 23 | "noops": 0, 24 | "retries": { 25 | "bulk": 0, 26 | "search": 0 27 | }, 28 | "throttled_millis": 0, 29 | "requests_per_second": -1, 30 | "throttled_until_millis": 0, 31 | "failures": [] 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | # 요청 40 | GET movie_dynamic_new/_search 41 | 42 | # 결과 43 | { 44 | "took": 1, 45 | "timed_out": false, 46 | "_shards": { 47 | "total": 5, 48 | "successful": 5, 49 | "skipped": 0, 50 | "failed": 0 51 | }, 52 | "hits": { 53 | "total": 2, 54 | "max_score": 1, 55 | "hits": [ 56 | { 57 | "_index": "movie_dynamic_new", 58 | "_type": "_doc", 59 | "_id": "1", 60 | "_score": 1, 61 | "_source": { 62 | "title": "살아남은 아이", 63 | "movieNmEn": "Last Child" 64 | } 65 | }, 66 | { 67 | "_index": "movie_dynamic_new", 68 | "_type": "_doc", 69 | "_id": "3", 70 | "_score": 1, 71 | "_source": { 72 | "title": "프렌즈: 몬스터섬의비밀" 73 | } 74 | } 75 | ] 76 | } 77 | } 78 | 79 | 80 | -------------------------------------------------------------------------------- /document/sample/chapter03/3.5/12.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST _reindex 3 | { 4 | "source": { 5 | "index": "movie_dynamic", 6 | "type": "_doc", 7 | "query": { 8 | "term": { 9 | "title.keyword": "프렌즈: 몬스터섬의비밀" 10 | } 11 | } 12 | }, 13 | "dest": { 14 | "index": "movie_dynamic_new" 15 | } 16 | } 17 | 18 | # 결과 19 | { 20 | "took": 248, 21 | "timed_out": false, 22 | "total": 1, 23 | "updated": 0, 24 | "created": 1, 25 | "deleted": 0, 26 | "batches": 1, 27 | "version_conflicts": 0, 28 | "noops": 0, 29 | "retries": { 30 | "bulk": 0, 31 | "search": 0 32 | }, 33 | "throttled_millis": 0, 34 | "requests_per_second": -1, 35 | "throttled_until_millis": 0, 36 | "failures": [] 37 | } 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | # 요청 46 | GET movie_dynamic_new/_search 47 | 48 | # 결과 49 | { 50 | "took": 1, 51 | "timed_out": false, 52 | "_shards": { 53 | "total": 5, 54 | "successful": 5, 55 | "skipped": 0, 56 | "failed": 0 57 | }, 58 | "hits": { 59 | "total": 1, 60 | "max_score": 1, 61 | "hits": [ 62 | { 63 | "_index": "movie_dynamic_new", 64 | "_type": "_doc", 65 | "_id": "3", 66 | "_score": 1, 67 | "_source": { 68 | "title": "프렌즈: 몬스터섬의비밀" 69 | } 70 | } 71 | ] 72 | } 73 | } -------------------------------------------------------------------------------- /document/sample/chapter04/4.2/09.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_search 3 | { 4 | "query": { 5 | "match": { 6 | "movieNm": { 7 | "query": "자전차왕 엄복동", 8 | "operator": "and" 9 | } 10 | } 11 | } 12 | } 13 | 14 | # 결과 15 | { 16 | "took" : 0, 17 | "timed_out" : false, 18 | "_shards" : { 19 | "total" : 5, 20 | "successful" : 5, 21 | "skipped" : 0, 22 | "failed" : 0 23 | }, 24 | "hits" : { 25 | "total" : 1, 26 | "max_score" : 2.52261, 27 | "hits" : [ 28 | { 29 | "_index" : "movie_search", 30 | "_type" : "_doc", 31 | "_id" : "9", 32 | "_score" : 2.52261, 33 | "_source" : { 34 | "movieCd" : "20176442", 35 | "movieNm" : "자전차왕 엄복동", 36 | "movieNmEn" : "", 37 | "prdtYear" : "2017", 38 | "openDt" : "", 39 | "typeNm" : "장편", 40 | "prdtStatNm" : "후반작업", 41 | "nationAlt" : "한국", 42 | "genreAlt" : "드라마", 43 | "repNationNm" : "한국", 44 | "repGenreNm" : "드라마", 45 | "directors" : [ ], 46 | "companys" : [ ] 47 | } 48 | } 49 | ] 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /document/sample/chapter04/4.2/10.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_search 3 | { 4 | "query": { 5 | "match": { 6 | "movieNm": { 7 | "query": "자전차왕 엄복동", 8 | "minimum_should_match": 2 9 | } 10 | } 11 | } 12 | } 13 | 14 | # 결과 15 | { 16 | "took" : 1, 17 | "timed_out" : false, 18 | "_shards" : { 19 | "total" : 5, 20 | "successful" : 5, 21 | "skipped" : 0, 22 | "failed" : 0 23 | }, 24 | "hits" : { 25 | "total" : 1, 26 | "max_score" : 2.52261, 27 | "hits" : [ 28 | { 29 | "_index" : "movie_search", 30 | "_type" : "_doc", 31 | "_id" : "9", 32 | "_score" : 2.52261, 33 | "_source" : { 34 | "movieCd" : "20176442", 35 | "movieNm" : "자전차왕 엄복동", 36 | "movieNmEn" : "", 37 | "prdtYear" : "2017", 38 | "openDt" : "", 39 | "typeNm" : "장편", 40 | "prdtStatNm" : "후반작업", 41 | "nationAlt" : "한국", 42 | "genreAlt" : "드라마", 43 | "repNationNm" : "한국", 44 | "repGenreNm" : "드라마", 45 | "directors" : [ ], 46 | "companys" : [ ] 47 | } 48 | } 49 | ] 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /document/sample/chapter04/4.3/06.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_search 3 | { 4 | "query" : { 5 | "query_string": { 6 | "default_field": "movieNm", 7 | "query": "(가정) AND (어린이 날)" 8 | } 9 | } 10 | } 11 | 12 | # 결과 13 | { 14 | "took": 1, 15 | "timed_out": false, 16 | "_shards": { 17 | "total": 5, 18 | "successful": 5, 19 | "skipped": 0, 20 | "failed": 0 21 | }, 22 | "hits": { 23 | "total": 0, 24 | "max_score": null, 25 | "hits": [] 26 | } 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /document/sample/chapter04/4.3/07.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_search 3 | { 4 | "query" : { 5 | "prefix": { 6 | "movieNm": "자전차" 7 | } 8 | } 9 | } 10 | 11 | # 결과 12 | { 13 | "took": 3, 14 | "timed_out": false, 15 | "_shards": { 16 | "total": 5, 17 | "successful": 5, 18 | "skipped": 0, 19 | "failed": 0 20 | }, 21 | "hits": { 22 | "total": 1, 23 | "max_score": 1, 24 | "hits": [ 25 | { 26 | "_index": "movie_search", 27 | "_type": "_doc", 28 | "_id": "GD3JqmkBjjM-ebDb8AQS", 29 | "_score": 1, 30 | "_source": { 31 | "movieCd": "20176442", 32 | "movieNm": "자전차왕 엄복동", 33 | "movieNmEn": "", 34 | "prdtYear": "2017", 35 | "openDt": "", 36 | "typeNm": "장편", 37 | "prdtStatNm": "후반작업", 38 | "nationAlt": "한국", 39 | "genreAlt": [ 40 | "드라마" 41 | ], 42 | "repNationNm": "한국", 43 | "repGenreNm": "드라마", 44 | "directors": [], 45 | "companys": [] 46 | } 47 | } 48 | ] 49 | } 50 | } -------------------------------------------------------------------------------- /document/sample/chapter04/4.4/01.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT _cluster/settings 3 | { 4 | "transient": { 5 | "cluster.routing.use_adaptive_replica_selection": true 6 | } 7 | } 8 | 9 | # 결과 10 | { 11 | "acknowledged" : true, 12 | "persistent" : { }, 13 | "transient" : { 14 | "cluster" : { 15 | "routing" : { 16 | "use_adaptive_replica_selection" : "true" 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /document/sample/chapter04/4.4/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT _cluster/settings 3 | { 4 | "transient": { 5 | "search.default_search_timeout": "1s" 6 | } 7 | } 8 | 9 | # 결과 10 | { 11 | "acknowledged": true, 12 | "persistent": {}, 13 | "transient": { 14 | "search": { 15 | "default_search_timeout": "1s" 16 | } 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /document/sample/chapter04/4.4/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_count?q=prdtYear:2017 3 | {} 4 | 5 | # 결과 6 | { 7 | "count": 2114, 8 | "_shards": { 9 | "total": 5, 10 | "successful": 5, 11 | "skipped": 0, 12 | "failed": 0 13 | } 14 | } 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | # 요청 24 | POST movie_search/_count 25 | { 26 | "query": { 27 | "query_string": { 28 | "default_field": "prdtYear", 29 | "query": "2017" 30 | } 31 | } 32 | } 33 | 34 | # 결과 35 | { 36 | "count": 2114, 37 | "_shards": { 38 | "total": 5, 39 | "successful": 5, 40 | "skipped": 0, 41 | "failed": 0 42 | } 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /document/sample/chapter04/4.4/06.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_validate/query?q=prdtYear:2017 3 | {} 4 | 5 | # 결과 6 | { 7 | "_shards" : { 8 | "total" : 1, 9 | "successful" : 1, 10 | "failed" : 0 11 | }, 12 | "valid" : true 13 | } 14 | 15 | 16 | 17 | 18 | 19 | # 요청 20 | POST movie_search/_validate/query 21 | { 22 | "query" : { 23 | "match": { 24 | "prdtYear": 2017 25 | } 26 | } 27 | } 28 | 29 | # 결과 30 | { 31 | "_shards" : { 32 | "total" : 1, 33 | "successful" : 1, 34 | "failed" : 0 35 | }, 36 | "valid" : true 37 | } 38 | -------------------------------------------------------------------------------- /document/sample/chapter04/4.4/07.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_search/_validate/query?rewrite=true 3 | { 4 | "query" : { 5 | "match": { 6 | "prdtYear": "2017-10-10" 7 | } 8 | } 9 | } 10 | 11 | # 결과 12 | { 13 | "_shards": { 14 | "total": 1, 15 | "successful": 1, 16 | "failed": 0 17 | }, 18 | "valid": false, 19 | "explanations": [{ 20 | "index": "movie_search", 21 | "valid": false, 22 | "error": "" " 23 | [movie_search/molsU_KAQkGhVZWTbt2qZQ] QueryShardException[failed to create query: { 24 | " match " : { 25 | " prdtYear " : { 26 | " query " : " 2017 - 10 - 10 ", 27 | " operator " : " OR ", 28 | " prefix_length " : 0, 29 | " max_expansions " : 50, 30 | " fuzzy_transpositions " : true, 31 | " lenient " : false, 32 | " zero_terms_query " : " NONE ", 33 | " auto_generate_synonyms_phrase_query " : true, 34 | " boost " : 1.0 35 | } 36 | } 37 | }]; nested: NumberFormatException[For input string: " 2017 - 10 - 10 "];; java.lang.NumberFormatException: For input string: " 2017 - 10 - 10 " 38 | " "" 39 | } 40 | ] 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.1/01.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search 2 | { 3 | "query": { 4 | "match_all": {} 5 | }, 6 | "aggs": { 7 | "region_count": { 8 | "terms": { 9 | "field": "geoip.region_name.keyword", 10 | "size": 20 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/01.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "total_bytes": { 5 | "sum": { 6 | "field": "bytes" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/02.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "total_bytes": { 12 | "sum": { 13 | "field": "bytes" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/03.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "total_bytes": { 12 | "sum": { 13 | "script": { 14 | "lang": "painless", 15 | "source": "doc.bytes.value" 16 | } 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/04.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "total_bytes": { 12 | "sum": { 13 | "script": { 14 | "lang": "painless", 15 | "source": "doc.bytes.value / params.divide_value", 16 | "params": { 17 | "divide_value": 1000 18 | } 19 | } 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/05.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "total_bytes": { 12 | "sum": { 13 | "script": { 14 | "lang": "painless", 15 | "source": "doc.bytes.value / (double)params.divide_value", 16 | "params": { 17 | "divide_value": 1000 18 | } 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/06.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "avg_bytes": { 5 | "avg": { 6 | "field": "bytes" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/07.txt: -------------------------------------------------------------------------------- 1 | GET _search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "avg_bytes": { 12 | "avg": { 13 | "field": "bytes" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/08.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "min_bytes": { 5 | "min": { 6 | "field": "bytes" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/09.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "min_bytes": { 12 | "min": { 13 | "field": "bytes" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/10.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "max_bytes": { 5 | "max": { 6 | "field": "bytes" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/11.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "max_bytes": { 12 | "max": { 13 | "field": "bytes" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/12.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "bytes_count": { 5 | "value_count": { 6 | "field": "bytes" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/13.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "bytes_count": { 12 | "value_count": { 13 | "field": "bytes" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/14.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "bytes_stats": { 5 | "stats": { 6 | "field": "bytes" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/15.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "bytes_stats": { 12 | "stats": { 13 | "field": "bytes" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/16.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "bytes_extended_stats": { 5 | "extended_stats": { 6 | "field": "bytes" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/17.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.city_name" : "Paris" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "bytes_extended_stats": { 12 | "extended_stats": { 13 | "field": "bytes" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/18.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.country_name" : "United States" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "us_city_names": { 12 | "terms": { 13 | "field": "geoip.city_name.keyword", 14 | "size": 20 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/19.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.country_name" : "United States" } 7 | } 8 | } 9 | }, 10 | "aggs": { 11 | "us_cardinality": { 12 | "cardinality": { 13 | "field": "geoip.city_name.keyword" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/20.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "bytes_percentiles": { 5 | "percentiles": { 6 | "field": "bytes" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/21.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "bytes_percentiles": { 5 | "percentiles": { 6 | "field": "bytes", 7 | "percents": [10, 20, 30, 40, 50, 60, 70, 80, 90] 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/22.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "bytes_percentile_ranks": { 5 | "percentile_ranks": { 6 | "field": "bytes", 7 | "values": [5000, 10000] 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/23.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log-applied-mapping/_mapping/field/geoip.location -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/24.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log-applied-mapping/_search?size=0 2 | { 3 | "aggs" : { 4 | "viewport" : { 5 | "geo_bounds" : { 6 | "field" : "geoip.location", 7 | "wrap_longitude" : true 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/25.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log-applied-mapping/_search?size=0 2 | { 3 | "query" : { 4 | "constant_score" : { 5 | "filter" : { 6 | "match" : { "geoip.continent_code" : "EU" } 7 | } 8 | } 9 | }, 10 | "aggs" : { 11 | "viewport" : { 12 | "geo_bounds" : { 13 | "field" : "geoip.location", 14 | "wrap_longitude" : true 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.2/26.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log-applied-mapping/_search?size=0 2 | { 3 | "aggs" : { 4 | "centroid" : { 5 | "geo_centroid" : { 6 | "field" : "geoip.location" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/01.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "bytes_range" : { 5 | "range": { 6 | "field": "bytes", 7 | "ranges": [ 8 | { 9 | "from": 1000, 10 | "to": 2000 11 | } 12 | ] 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/02.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "bytes_range" : { 5 | "range": { 6 | "field": "bytes", 7 | "ranges": [ 8 | { 9 | "to": 1000 10 | }, 11 | { 12 | "from": 1000, 13 | "to": 2000 14 | }, 15 | { 16 | "from": 2000, 17 | "to": 3000 18 | } 19 | ] 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/03.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "bytes_range" : { 5 | "range": { 6 | "field": "bytes", 7 | "ranges": [ 8 | { 9 | "key": "small", 10 | "to": 1000 11 | }, 12 | { 13 | "key": "medium", 14 | "from": 1000, 15 | "to": 2000 16 | }, 17 | { 18 | "key": "large", 19 | "from": 2000, 20 | "to": 3000 21 | } 22 | ] 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/04.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "request count with date range" : { 5 | "date_range": { 6 | "field": "timestamp", 7 | "ranges": [ 8 | { 9 | "from": "2015-01-04T05:14:00.000Z", 10 | "to": "2015-01-04T05:16:00.000Z" 11 | } 12 | ] 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/05.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "bytes_histogram" : { 5 | "histogram" : { 6 | "field" : "bytes", 7 | "interval": 10000 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/06.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "bytes_histogram" : { 5 | "histogram" : { 6 | "field" : "bytes", 7 | "interval": 10000, 8 | "min_doc_count": 1 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/07.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "daily_request_count" : { 5 | "date_histogram": { 6 | "field": "timestamp", 7 | "interval": "minute" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/08.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "daily_request_count" : { 5 | "date_histogram": { 6 | "field": "timestamp", 7 | "interval": "day", 8 | "format": "yyyy-MM-dd" 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/09.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "daily_request_count" : { 5 | "date_histogram": { 6 | "field": "timestamp", 7 | "interval": "day" 8 | } 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/10.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "daily_request_count" : { 5 | "date_histogram": { 6 | "field": "timestamp", 7 | "interval": "day", 8 | "offset": "+3h" 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/11.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "request count by country" : { 5 | "terms" : { 6 | "field" : "geoip.country_name.keyword" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.3/12.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs" : { 4 | "request count by country" : { 5 | "terms" : { 6 | "field" : "geoip.country_name.keyword", 7 | "size": 100 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.4/01.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "histo": { 5 | "date_histogram": { 6 | "field": "timestamp", 7 | "interval": "minute" 8 | }, 9 | "aggs": { 10 | "bytes_sum": { 11 | "sum": { 12 | "field": "bytes" 13 | } 14 | } 15 | } 16 | }, 17 | "max_bytes": { 18 | "max_bucket": { 19 | "buckets_path": "histo>bytes_sum" 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /document/sample/chapter05/5.4/02.txt: -------------------------------------------------------------------------------- 1 | GET /apache-web-log/_search?size=0 2 | { 3 | "aggs": { 4 | "histo": { 5 | "date_histogram": { 6 | "field": "timestamp", 7 | "interval": "day" 8 | }, 9 | "aggs": { 10 | "bytes_sum": { 11 | "sum": { 12 | "field": "bytes" 13 | } 14 | }, 15 | "sum_deriv": { 16 | "derivative": { 17 | "buckets_path": "bytes_sum" 18 | } 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.1/01.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT /seunjeon_default_analyzer 3 | { 4 | "settings": { 5 | "number_of_shards": 5, 6 | "number_of_replicas": 1, 7 | "index": { 8 | "analysis": { 9 | "analyzer": { 10 | "korean": { 11 | "type": "custom", 12 | "tokenizer": "seunjeon_default_tokenizer" 13 | } 14 | }, 15 | "tokenizer": { 16 | "seunjeon_default_tokenizer": { 17 | "type": "seunjeon_tokenizer", 18 | "index_eojeol": false, 19 | "user_words": [ 20 | "낄끼+빠빠,-100", "c\\+\\+", "어그로", "버카충", "abc마트" 21 | ] 22 | } 23 | } 24 | } 25 | } 26 | } 27 | } 28 | 29 | # 결과 30 | { 31 | "acknowledged": true, 32 | "shards_acknowledged": true, 33 | "index": "seunjeon_default_analyzer" 34 | } 35 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.1/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT /seunjeon_with_dic_analyzer 3 | { 4 | "settings": { 5 | "index": { 6 | "analysis": { 7 | "tokenizer": { 8 | "seunjeon_default_tokenizer": { 9 | "index_eojeol": "false", 10 | "pos_tagging": "false", 11 | "user_dict_path": "dic/user_dic.csv", 12 | "type": "seunjeon_tokenizer" 13 | } 14 | }, 15 | "analyzer": { 16 | "korean": { 17 | "filter": [ 18 | "lowercase" 19 | ], 20 | "tokenizer": "seunjeon_default_tokenizer", 21 | "type": "custom" 22 | } 23 | } 24 | } 25 | } 26 | } 27 | } 28 | 29 | # 결과 30 | { 31 | "acknowledged": true, 32 | "shards_acknowledged": true, 33 | "index": "seunjeon_with_dic_analyzer" 34 | } 35 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.1/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT nori_analyzer 3 | { 4 | "settings": { 5 | "index": { 6 | "analysis": { 7 | "tokenizer": { 8 | "nori_user_dict_tokenizer": { 9 | "type": "nori_tokenizer", 10 | "decompound_mode": "mixed", 11 | "user_dictionary": "userdict_ko.txt" 12 | } 13 | }, 14 | "analyzer": { 15 | "nori_token_analyzer": { 16 | "type": "custom", 17 | "tokenizer": "nori_user_dict_tokenizer" 18 | } 19 | } 20 | } 21 | } 22 | } 23 | } 24 | 25 | # 결과 26 | { 27 | "acknowledged": true, 28 | "shards_acknowledged": true, 29 | "index": "nori_analyzer" 30 | } 31 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.1/07.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT nori_readingform 3 | { 4 | "settings": { 5 | "index":{ 6 | "analysis":{ 7 | "analyzer" : { 8 | "nori_readingform_analyzer" : { 9 | "tokenizer" : "nori_tokenizer", 10 | "filter" : ["nori_readingform"] 11 | } 12 | } 13 | } 14 | } 15 | } 16 | } 17 | 18 | # 결과 19 | { 20 | "acknowledged": true, 21 | "shards_acknowledged": true, 22 | "index": "nori_readingform" 23 | } -------------------------------------------------------------------------------- /document/sample/chapter06/6.1/08.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST nori_readingform/_analyze 3 | { 4 | "analyzer": "nori_readingform_analyzer", 5 | "text": "中國" 6 | } 7 | 8 | # 결과 9 | { 10 | "tokens": [ 11 | { 12 | "token": "중국", 13 | "start_offset": 0, 14 | "end_offset": 2, 15 | "type": "word", 16 | "position": 0 17 | } 18 | ] 19 | } 20 | 21 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.1/09.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT nori_full_analyzer 3 | { 4 | "mappings": { 5 | "_doc": { 6 | "properties": { 7 | "description": { 8 | "type": "text", 9 | "analyzer": "korean_analyzer" 10 | } 11 | } 12 | } 13 | }, 14 | "settings": { 15 | "index": { 16 | "analysis": { 17 | "analyzer": { 18 | "korean_analyzer": { 19 | "filter": [ 20 | "pos_filter_speech", 21 | "nori_readingform", 22 | "lowercase" 23 | ], 24 | "tokenizer": "nori_tokenizer" 25 | } 26 | }, 27 | "filter": { 28 | "pos_filter_speech": { 29 | "type": "nori_part_of_speech", 30 | "stoptags": [ 31 | "E", 32 | "IC", 33 | "J", 34 | "MAG", 35 | "MAJ", 36 | "MM", 37 | "NA", 38 | "NR", 39 | "SC", 40 | "SE", 41 | "SF", 42 | "SH", 43 | "SL", 44 | "SN", 45 | "SP", 46 | "SSC", 47 | "SSO", 48 | "SY", 49 | "UNA", 50 | "UNKNOWN", 51 | "VA", 52 | "VCN", 53 | "VCP", 54 | "VSV", 55 | "VV", 56 | "VX", 57 | "XPN", 58 | "XR", 59 | "XSA", 60 | "XSN", 61 | "XSV" 62 | ] 63 | } 64 | } 65 | } 66 | } 67 | } 68 | } 69 | 70 | # 결과 71 | { 72 | "acknowledged" : true, 73 | "shards_acknowledged" : true, 74 | "index" : "nori_full_analyzer" 75 | } 76 | 77 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/01.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_highlighting/_doc/1 3 | { 4 | "title": "Harry Potter and the Deathly Hallows" 5 | } 6 | 7 | # 결과 8 | { 9 | "_index": "movie_highlighting", 10 | "_type": "_doc", 11 | "_id": "1", 12 | "_version": 1, 13 | "result": "created", 14 | "_shards": { 15 | "total": 2, 16 | "successful": 1, 17 | "failed": 0 18 | }, 19 | "_seq_no": 0, 20 | "_primary_term": 1 21 | } 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_highlighting/_search 3 | { 4 | "query": { 5 | "match": { 6 | "title": { 7 | "query": "harry" 8 | } 9 | } 10 | }, 11 | "highlight": { 12 | "fields" : { 13 | "title" : {} 14 | } 15 | } 16 | } 17 | 18 | # 결과 19 | { 20 | "took": 102, 21 | "timed_out": false, 22 | "_shards": { 23 | "total": 5, 24 | "successful": 5, 25 | "skipped": 0, 26 | "failed": 0 27 | }, 28 | "hits": { 29 | "total": 1, 30 | "max_score": 0.2876821, 31 | "hits": [ 32 | { 33 | "_index": "movie_highlighting", 34 | "_type": "_doc", 35 | "_id": "1", 36 | "_score": 0.2876821, 37 | "_source": { 38 | "title": "Harry Potter and the Deathly Hallows" 39 | }, 40 | "highlight": { 41 | "title": [ 42 | "Harry Potter and the Deathly Hallows" 43 | ] 44 | } 45 | } 46 | ] 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_highlighting/_search 3 | { 4 | "query": { 5 | "match": { 6 | "title": { 7 | "query": "harry" 8 | } 9 | } 10 | }, 11 | "highlight": { 12 | "pre_tags": [ 13 | "" 14 | ], 15 | "post_tags": [ 16 | "" 17 | ], 18 | "fields": { 19 | "title": {} 20 | } 21 | } 22 | } 23 | 24 | # 결과 25 | { 26 | "took": 8, 27 | "timed_out": false, 28 | "_shards": { 29 | "total": 5, 30 | "successful": 5, 31 | "skipped": 0, 32 | "failed": 0 33 | }, 34 | "hits": { 35 | "total": 1, 36 | "max_score": 0.2876821, 37 | "hits": [ 38 | { 39 | "_index": "movie_highlighting", 40 | "_type": "_doc", 41 | "_id": "1", 42 | "_score": 0.2876821, 43 | "_source": { 44 | "title": "Harry Potter and the Deathly Hallows" 45 | }, 46 | "highlight": { 47 | "title": [ 48 | "Harry Potter and the Deathly Hallows" 49 | ] 50 | } 51 | } 52 | ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_script/_doc/1 3 | { 4 | "movieList": { 5 | "Death_Wish": 5.5, 6 | "About_Time": 7, 7 | "Suits": 3.5 8 | } 9 | } 10 | 11 | # 결과 12 | { 13 | "_index": "movie_script", 14 | "_type": "_doc", 15 | "_id": "1", 16 | "_version": 2, 17 | "result": "updated", 18 | "_shards": { 19 | "total": 2, 20 | "successful": 1, 21 | "failed": 0 22 | }, 23 | "_seq_no": 1, 24 | "_primary_term": 1 25 | } 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_script/_doc/1/_update 3 | { 4 | "script": "ctx._source.movieList.Black_Panther = 3.7" 5 | } 6 | 7 | # 결과 8 | { 9 | "_index": "movie_script", 10 | "_type": "_doc", 11 | "_id": "1", 12 | "_version": 2, 13 | "result": "updated", 14 | "_shards": { 15 | "total": 2, 16 | "successful": 1, 17 | "failed": 0 18 | }, 19 | "_seq_no": 1, 20 | "_primary_term": 1 21 | } 22 | 23 | 24 | 25 | 26 | 27 | 28 | # 요청 29 | GET movie_script/_doc/_search 30 | 31 | # 결과 32 | { 33 | "took": 6, 34 | "timed_out": false, 35 | "_shards": { 36 | "total": 5, 37 | "successful": 5, 38 | "skipped": 0, 39 | "failed": 0 40 | }, 41 | "hits": { 42 | "total": 1, 43 | "max_score": 1, 44 | "hits": [ 45 | { 46 | "_index": "movie_script", 47 | "_type": "_doc", 48 | "_id": "1", 49 | "_score": 1, 50 | "_source": { 51 | "movieList": { 52 | "Death_Wish": 5.5, 53 | "About_Time": 7, 54 | "Suits": 3.5, 55 | "Black_Panther": 3.7 56 | } 57 | } 58 | } 59 | ] 60 | } 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/06.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_script/_doc/1/_update 3 | { 4 | "script": "ctx._source.movieList.remove(\"Suits\")" 5 | } 6 | 7 | # 결과 8 | { 9 | "_index": "movie_script", 10 | "_type": "_doc", 11 | "_id": "1", 12 | "_version": 3, 13 | "result": "updated", 14 | "_shards": { 15 | "total": 2, 16 | "successful": 1, 17 | "failed": 0 18 | }, 19 | "_seq_no": 2, 20 | "_primary_term": 1 21 | } 22 | 23 | 24 | 25 | 26 | 27 | # 요청 28 | GET movie_script/_doc/_search 29 | 30 | # 결과 31 | { 32 | "took": 1, 33 | "timed_out": false, 34 | "_shards": { 35 | "total": 5, 36 | "successful": 5, 37 | "skipped": 0, 38 | "failed": 0 39 | }, 40 | "hits": { 41 | "total": 1, 42 | "max_score": 1, 43 | "hits": [ 44 | { 45 | "_index": "movie_script", 46 | "_type": "_doc", 47 | "_id": "1", 48 | "_score": 1, 49 | "_source": { 50 | "movieList": { 51 | "Death_Wish": 5.5, 52 | "About_Time": 7, 53 | "Black_Panther": 3.7 54 | } 55 | } 56 | } 57 | ] 58 | } 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/07.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST _scripts/movie_search_example_teamplate 3 | { 4 | "script": { 5 | "lang": "mustache", 6 | "source": { 7 | "query": { 8 | "match": { 9 | "movieNm": "{{ movie_name }}" 10 | } 11 | } 12 | } 13 | } 14 | } 15 | 16 | # 결과 17 | { 18 | "acknowledged": true 19 | } 20 | 21 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/08.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | GET _scripts/movie_search_example_teamplate 3 | 4 | # 결과 5 | { 6 | "_id": "movie_search_example_teamplate", 7 | "found": true, 8 | "script": { 9 | "lang": "mustache", 10 | "source": "{\"query\":{\"match\":{\"movieNm\":\"{{ movie_name }}\"}}}", 11 | "options": { 12 | "content_type": "application/json; charset=UTF-8" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/09.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_template_test/_doc/1 3 | { 4 | "movieNm": "titanic" 5 | } 6 | 7 | # 결과 8 | { 9 | "_index": "movie_template_test", 10 | "_type": "_doc", 11 | "_id": "1", 12 | "_version": 1, 13 | "result": "created", 14 | "_shards": { 15 | "total": 2, 16 | "successful": 1, 17 | "failed": 0 18 | }, 19 | "_seq_no": 0, 20 | "_primary_term": 1 21 | } 22 | 23 | 24 | 25 | 26 | 27 | 28 | # 요청 29 | POST movie_template_test/_doc/_search/template 30 | { 31 | "id": "movie_search_example_teamplate", 32 | "params": { 33 | "movie_name": "titanic" 34 | } 35 | } 36 | 37 | # 결과 38 | { 39 | "took": 1, 40 | "timed_out": false, 41 | "_shards": { 42 | "total": 5, 43 | "successful": 5, 44 | "skipped": 0, 45 | "failed": 0 46 | }, 47 | "hits": { 48 | "total": 1, 49 | "max_score": 0.2876821, 50 | "hits": [ 51 | { 52 | "_index": "movie_template_test", 53 | "_type": "_doc", 54 | "_id": "1", 55 | "_score": 0.2876821, 56 | "_source": { 57 | "movieNm": "titanic" 58 | } 59 | } 60 | ] 61 | } 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /document/sample/chapter06/6.2/10.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST _reindex 3 | { 4 | "source": { 5 | "index": "movie_search" 6 | }, 7 | "dest": { 8 | "index": "movie_info" 9 | } 10 | } 11 | 12 | # 결과 13 | { 14 | "took": 3443, 15 | "timed_out": false, 16 | "total": 63069, 17 | "updated": 0, 18 | "created": 63069, 19 | "deleted": 0, 20 | "batches": 64, 21 | "version_conflicts": 0, 22 | "noops": 0, 23 | "retries": { 24 | "bulk": 0, 25 | "search": 0 26 | }, 27 | "throttled_millis": 0, 28 | "requests_per_second": -1, 29 | "throttled_until_millis": 0, 30 | "failures": [] 31 | } 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.1/01.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT movie_term_suggest/_doc/1 3 | { 4 | "movieNm": "lover" 5 | } 6 | 7 | # 요청 8 | PUT movie_term_suggest/_doc/2 9 | { 10 | "movieNm": "Fall love" 11 | } 12 | 13 | # 요청 14 | PUT movie_term_suggest/_doc/3 15 | { 16 | "movieNm": "lovely" 17 | } 18 | 19 | # 요청 20 | PUT movie_term_suggest/_doc/4 21 | { 22 | "movieNm": "lovestory" 23 | } 24 | 25 | 26 | 27 | 28 | 29 | # 요청 30 | GET movie_term_suggest/_search 31 | 32 | # 결과 33 | { 34 | "took": 53, 35 | "timed_out": false, 36 | "_shards": { 37 | "total": 5, 38 | "successful": 5, 39 | "skipped": 0, 40 | "failed": 0 41 | }, 42 | "hits": { 43 | "total": 4, 44 | "max_score": 1, 45 | "hits": [ 46 | { 47 | "_index": "movie_term_suggest", 48 | "_type": "_doc", 49 | "_id": "2", 50 | "_score": 1, 51 | "_source": { 52 | "movieNm": "Fall love" 53 | } 54 | }, 55 | { 56 | "_index": "movie_term_suggest", 57 | "_type": "_doc", 58 | "_id": "4", 59 | "_score": 1, 60 | "_source": { 61 | "movieNm": "lovestory" 62 | } 63 | }, 64 | { 65 | "_index": "movie_term_suggest", 66 | "_type": "_doc", 67 | "_id": "1", 68 | "_score": 1, 69 | "_source": { 70 | "movieNm": "lover" 71 | } 72 | }, 73 | { 74 | "_index": "movie_term_suggest", 75 | "_type": "_doc", 76 | "_id": "3", 77 | "_score": 1, 78 | "_source": { 79 | "movieNm": "lovely" 80 | } 81 | } 82 | ] 83 | } 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.1/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST moive_term_suggest/_search 3 | { 4 | "suggest": { 5 | "spell-suggestion": { 6 | "text": "lave", 7 | "term": { 8 | "field": "movieNm" 9 | } 10 | } 11 | } 12 | } 13 | 14 | # 결과 15 | { 16 | "took": 35, 17 | "timed_out": false, 18 | "_shards": { 19 | "total": 5, 20 | "successful": 5, 21 | "skipped": 0, 22 | "failed": 0 23 | }, 24 | "hits": { 25 | "total": 0, 26 | "max_score": 0, 27 | "hits": [] 28 | }, 29 | "suggest": { 30 | "spell-suggestion": [ 31 | { 32 | "text": "lave", 33 | "offset": 0, 34 | "length": 4, 35 | "options": [ 36 | { 37 | "text": "love", 38 | "score": 0.75, 39 | "freq": 1 40 | }, 41 | { 42 | "text": "lover", 43 | "score": 0.5, 44 | "freq": 1 45 | } 46 | ] 47 | } 48 | ] 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.1/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST movie_term_completion/_search 3 | { 4 | "suggest": { 5 | "movie_completion": { 6 | "prefix": "l", 7 | "completion": { 8 | "field": "movieNmEnComple", 9 | "size": 5 10 | } 11 | } 12 | } 13 | } 14 | 15 | # 결과 16 | { 17 | "took": 12, 18 | "timed_out": false, 19 | "_shards": { 20 | "total": 5, 21 | "successful": 5, 22 | "skipped": 0, 23 | "failed": 0 24 | }, 25 | "hits": { 26 | "total": 0, 27 | "max_score": 0, 28 | "hits": [] 29 | }, 30 | "suggest": { 31 | "movie_completion": [ 32 | { 33 | "text": "l", 34 | "offset": 0, 35 | "length": 1, 36 | "options": [ 37 | { 38 | "text": "Love for a mother", 39 | "_index": "movie_term_completion", 40 | "_type": "_doc", 41 | "_id": "3", 42 | "_score": 1, 43 | "_source": { 44 | "movieNmEnComple": "Love for a mother" 45 | } 46 | }, 47 | { 48 | "text": "Lover", 49 | "_index": "movie_term_completion", 50 | "_type": "_doc", 51 | "_id": "2", 52 | "_score": 1, 53 | "_source": { 54 | "movieNmEnComple": "Lover" 55 | } 56 | } 57 | ] 58 | } 59 | ] 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.2/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST /company_spellchecker/_doc/_search 3 | { 4 | "suggest": { 5 | "my-suggestion": { 6 | "text": "샴성전자", 7 | "term": { 8 | "field": "suggest" 9 | } 10 | } 11 | } 12 | } 13 | 14 | # 결과 15 | { 16 | "took": 58, 17 | "timed_out": false, 18 | "_shards": { 19 | "total": 5, 20 | "successful": 5, 21 | "skipped": 0, 22 | "failed": 0 23 | }, 24 | "hits": { 25 | "total": 0, 26 | "max_score": 0, 27 | "hits": [] 28 | }, 29 | "suggest": { 30 | "my-suggestion": [ 31 | { 32 | "text": "ㅅㅑㅁㅅㅓㅇㅈㅓㄴㅈㅏ", 33 | "offset": 0, 34 | "length": 4, 35 | "options": [ 36 | { 37 | "text": "ㅅㅏㅁㅅㅓㅇㅈㅓㄴㅈㅏ", 38 | "score": 0.9090909, 39 | "freq": 1 40 | } 41 | ] 42 | } 43 | ] 44 | } 45 | } -------------------------------------------------------------------------------- /document/sample/chapter07/7.2/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT /company 3 | { 4 | "settings": { 5 | "index": { 6 | "analysis": { 7 | "analyzer": { 8 | "my_analyzer": { 9 | "type": "custom", 10 | "tokenizer": "standard", 11 | "filter": [ 12 | "trim", 13 | "lowercase" 14 | ] 15 | } 16 | } 17 | } 18 | } 19 | } 20 | } 21 | 22 | # 결과 23 | { 24 | "acknowledged": true, 25 | "shards_acknowledged": true, 26 | "index": "company" 27 | } 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | # 요청 36 | PUT /company/_doc/_mappings 37 | { 38 | "properties": { 39 | "name": { 40 | "type": "keyword" 41 | } 42 | } 43 | } 44 | 45 | # 결과 46 | { 47 | "acknowledged": true 48 | } 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | # 요청 57 | PUT /search_keyword 58 | { 59 | "settings": { 60 | "index": { 61 | "analysis": { 62 | "analyzer": { 63 | "kor2eng_analyzer": { 64 | "type": "custom", 65 | "tokenizer": "standard", 66 | "filter": [ 67 | "trim", 68 | "lowercase", 69 | "javacafe_kor2eng" 70 | ] 71 | }, 72 | "eng2kor_analyzer": { 73 | "type": "custom", 74 | "tokenizer": "standard", 75 | "filter": [ 76 | "trim", 77 | "lowercase", 78 | "javacafe_eng2kor" 79 | ] 80 | } 81 | } 82 | } 83 | } 84 | } 85 | } 86 | 87 | # 결과 88 | { 89 | "acknowledged": true, 90 | "shards_acknowledged": true, 91 | "index": "search_keyword" 92 | } 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | # 요청 102 | PUT search_keyword/_doc/_mapping 103 | { 104 | "properties": { 105 | "name": { 106 | "type": "keyword", 107 | "copy_to": ["kor2eng_suggest", "eng2kor_suggest"] 108 | }, 109 | "kor2eng_suggest": { 110 | "type": "text", 111 | "analyzer": "standard", 112 | "search_analyzer": "kor2eng_analyzer" 113 | }, 114 | "eng2kor_suggest": { 115 | "type": "text", 116 | "analyzer": "standard", 117 | "search_analyzer": "eng2kor_analyzer" 118 | } 119 | } 120 | } 121 | 122 | # 결과 123 | { 124 | "acknowledged": true 125 | } 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.2/04.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT /company/_doc/1 3 | { 4 | "name" : "삼성전자" 5 | } 6 | 7 | # 요청 8 | PUT /company/_doc/2 9 | { 10 | "name" : "iphone" 11 | } 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | # 요청 20 | GET /company/_search 21 | 22 | # 결과 23 | { 24 | "took": 1, 25 | "timed_out": false, 26 | "_shards": { 27 | "total": 5, 28 | "successful": 5, 29 | "skipped": 0, 30 | "failed": 0 31 | }, 32 | "hits": { 33 | "total": 2, 34 | "max_score": 1, 35 | "hits": [ 36 | { 37 | "_index": "company", 38 | "_type": "_doc", 39 | "_id": "2", 40 | "_score": 1, 41 | "_source": { 42 | "name": "iphone" 43 | } 44 | }, 45 | { 46 | "_index": "company", 47 | "_type": "_doc", 48 | "_id": "1", 49 | "_score": 1, 50 | "_source": { 51 | "name": "삼성전자" 52 | } 53 | } 54 | ] 55 | } 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.2/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | PUT /search_keyword/_doc/1 3 | { 4 | "name" : "삼성전자" 5 | } 6 | 7 | # 요청 8 | PUT /search_keyword/_doc/2 9 | { 10 | "name" : "iphone" 11 | } 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | # 요청 20 | GET /search_keyword/_search 21 | 22 | # 결과 23 | { 24 | "took": 2, 25 | "timed_out": false, 26 | "_shards": { 27 | "total": 5, 28 | "successful": 5, 29 | "skipped": 0, 30 | "failed": 0 31 | }, 32 | "hits": { 33 | "total": 2, 34 | "max_score": 1, 35 | "hits": [ 36 | { 37 | "_index": "search_keyword", 38 | "_type": "_doc", 39 | "_id": "2", 40 | "_score": 1, 41 | "_source": { 42 | "name": "iphone" 43 | } 44 | }, 45 | { 46 | "_index": "search_keyword", 47 | "_type": "_doc", 48 | "_id": "1", 49 | "_score": 1, 50 | "_source": { 51 | "name": "삼성전자" 52 | } 53 | } 54 | ] 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.2/06.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST /search_keyword/_search 3 | { 4 | "query": { 5 | "match": { 6 | "eng2kor_suggest": { 7 | "query": "tkatjdwjswk" 8 | } 9 | } 10 | } 11 | } 12 | 13 | # 결과 14 | { 15 | "took": 1, 16 | "timed_out": false, 17 | "_shards": { 18 | "total": 5, 19 | "successful": 5, 20 | "skipped": 0, 21 | "failed": 0 22 | }, 23 | "hits": { 24 | "total": 1, 25 | "max_score": 0.2876821, 26 | "hits": [ 27 | { 28 | "_index": "search_keyword", 29 | "_type": "_doc", 30 | "_id": "1", 31 | "_score": 0.2876821, 32 | "_source": { 33 | "name": "삼성전자" 34 | } 35 | } 36 | ] 37 | } 38 | } 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | # 요청 48 | POST /search_keyword/_search 49 | { 50 | "query": { 51 | "match": { 52 | "kor2eng_suggest": { 53 | "query": "ㅑㅔㅗㅐㅜㄷ" 54 | } 55 | } 56 | } 57 | } 58 | 59 | 60 | # 결과 61 | { 62 | "took": 2, 63 | "timed_out": false, 64 | "_shards": { 65 | "total": 5, 66 | "successful": 5, 67 | "skipped": 0, 68 | "failed": 0 69 | }, 70 | "hits": { 71 | "total": 1, 72 | "max_score": 0.2876821, 73 | "hits": [ 74 | { 75 | "_index": "search_keyword", 76 | "_type": "_doc", 77 | "_id": "2", 78 | "_score": 0.2876821, 79 | "_source": { 80 | "name": "iphone" 81 | } 82 | } 83 | ] 84 | } 85 | } 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.3/7.3.1/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | GET /ac_test/_search 3 | 4 | # 결과 5 | { 6 | "took": 1, 7 | "timed_out": false, 8 | "_shards": { 9 | "total": 5, 10 | "successful": 5, 11 | "skipped": 0, 12 | "failed": 0 13 | }, 14 | "hits": { 15 | "total": 3, 16 | "max_score": 1, 17 | "hits": [ 18 | { 19 | "_index": "ac_test", 20 | "_type": "ac_test", 21 | "_id": "2", 22 | "_score": 1, 23 | "_source": { 24 | "itemSrc": "신혼가전", 25 | "itemCompletion": "신혼가전" 26 | } 27 | }, 28 | { 29 | "_index": "ac_test", 30 | "_type": "ac_test", 31 | "_id": "1", 32 | "_score": 1, 33 | "_source": { 34 | "itemSrc": "신혼", 35 | "itemCompletion": "신혼" 36 | } 37 | }, 38 | { 39 | "_index": "ac_test", 40 | "_type": "ac_test", 41 | "_id": "3", 42 | "_score": 1, 43 | "_source": { 44 | "itemSrc": "신혼가전특별전", 45 | "itemCompletion": "신혼가전특별전" 46 | } 47 | } 48 | ] 49 | } 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.3/7.3.1/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST /ac_test/_search 3 | { 4 | "query": { 5 | "match" : { 6 | "itemSrc" : "신혼" 7 | } 8 | } 9 | } 10 | 11 | # 결과 12 | { 13 | "took": 1, 14 | "timed_out": false, 15 | "_shards": { 16 | "total": 5, 17 | "successful": 5, 18 | "skipped": 0, 19 | "failed": 0 20 | }, 21 | "hits": { 22 | "total": 1, 23 | "max_score": 0.2876821, 24 | "hits": [ 25 | { 26 | "_index": "ac_test", 27 | "_type": "ac_test", 28 | "_id": "1", 29 | "_score": 0.2876821, 30 | "_source": { 31 | "itemSrc": "신혼", 32 | "itemCompletion": "신혼" 33 | } 34 | } 35 | ] 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.3/7.3.3.2/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | GET /ac_test2/_search 3 | 4 | # 결과 5 | { 6 | "took": 2, 7 | "timed_out": false, 8 | "_shards": { 9 | "total": 5, 10 | "successful": 5, 11 | "skipped": 0, 12 | "failed": 0 13 | }, 14 | "hits": { 15 | "total": 3, 16 | "max_score": 1, 17 | "hits": [ 18 | { 19 | "_index": "ac_test2", 20 | "_type": "ac_test2", 21 | "_id": "2", 22 | "_score": 1, 23 | "_source": { 24 | "item": "신혼가전", 25 | "itemNgram": "신혼가전", 26 | "itemNgramEdge": "신혼가전", 27 | "itemNgramEdgeBack": "신혼가전" 28 | } 29 | }, 30 | { 31 | "_index": "ac_test2", 32 | "_type": "ac_test2", 33 | "_id": "1", 34 | "_score": 1, 35 | "_source": { 36 | "item": "신혼", 37 | "itemNgram": "신혼", 38 | "itemNgramEdge": "신혼", 39 | "itemNgramEdgeBack": "신혼" 40 | } 41 | }, 42 | { 43 | "_index": "ac_test2", 44 | "_type": "ac_test2", 45 | "_id": "3", 46 | "_score": 1, 47 | "_source": { 48 | "item": "신혼가전특별전", 49 | "itemNgram": "신혼가전특별전", 50 | "itemNgramEdge": "신혼가전특별전", 51 | "itemNgramEdgeBack": "신혼가전특별전" 52 | } 53 | } 54 | ] 55 | } 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.3/7.3.3.2/05.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST /ac_test2/_search 3 | { 4 | "query" : { 5 | "bool" : { 6 | "should" : [{ 7 | "prefix" : { 8 | "item" : "가전" 9 | } 10 | }, { 11 | "term" : { 12 | "itemNgram" : "가전" 13 | } 14 | }, { 15 | "term" : { 16 | "itemNgramEdge" : "가전" 17 | } 18 | }, { 19 | "term" : { 20 | "itemNgramEdgeBack" : "가전" 21 | } 22 | }], 23 | "minimum_should_match" : 1 24 | } 25 | } 26 | } 27 | 28 | # 결과 29 | { 30 | "took": 2, 31 | "timed_out": false, 32 | "_shards": { 33 | "total": 5, 34 | "successful": 5, 35 | "skipped": 0, 36 | "failed": 0 37 | }, 38 | "hits": { 39 | "total": 2, 40 | "max_score": 1.278063, 41 | "hits": [ 42 | { 43 | "_index": "ac_test2", 44 | "_type": "ac_test2", 45 | "_id": "3", 46 | "_score": 1.278063, 47 | "_source": { 48 | "item": "신혼가전특별전", 49 | "itemNgram": "신혼가전특별전", 50 | "itemNgramEdge": "신혼가전특별전", 51 | "itemNgramEdgeBack": "신혼가전특별전" 52 | } 53 | }, 54 | { 55 | "_index": "ac_test2", 56 | "_type": "ac_test2", 57 | "_id": "2", 58 | "_score": 1.2443117, 59 | "_source": { 60 | "item": "신혼가전", 61 | "itemNgram": "신혼가전", 62 | "itemNgramEdge": "신혼가전", 63 | "itemNgramEdgeBack": "신혼가전" 64 | } 65 | } 66 | ] 67 | } 68 | } 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.3/7.3.3.3/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | GET /ac_test3/_search 3 | 4 | # 결과 5 | { 6 | "took": 2, 7 | "timed_out": false, 8 | "_shards": { 9 | "total": 5, 10 | "successful": 5, 11 | "skipped": 0, 12 | "failed": 0 13 | }, 14 | "hits": { 15 | "total": 3, 16 | "max_score": 1, 17 | "hits": [ 18 | { 19 | "_index": "ac_test3", 20 | "_type": "ac_test3", 21 | "_id": "2", 22 | "_score": 1, 23 | "_source": { 24 | "item": "신혼가전", 25 | "itemChosung": "신혼가전" 26 | } 27 | }, 28 | { 29 | "_index": "ac_test3", 30 | "_type": "ac_test3", 31 | "_id": "1", 32 | "_score": 1, 33 | "_source": { 34 | "item": "신혼", 35 | "itemChosung": "신혼" 36 | } 37 | }, 38 | { 39 | "_index": "ac_test3", 40 | "_type": "ac_test3", 41 | "_id": "3", 42 | "_score": 1, 43 | "_source": { 44 | "item": "신혼가전특별전", 45 | "itemChosung": "신혼가전특별전" 46 | } 47 | } 48 | ] 49 | } 50 | } 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.3/7.3.3.3/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST /ac_test3/_search 3 | { 4 | "query" : { 5 | "bool" : { 6 | "should" : [{ 7 | "term" : { 8 | "itemChosung" : "ㅅㅎㄱㅈ" 9 | } 10 | }], 11 | "minimum_should_match" : 1 12 | } 13 | } 14 | } 15 | 16 | # 결과 17 | { 18 | "took": 1, 19 | "timed_out": false, 20 | "_shards": { 21 | "total": 5, 22 | "successful": 5, 23 | "skipped": 0, 24 | "failed": 0 25 | }, 26 | "hits": { 27 | "total": 2, 28 | "max_score": 4.430304, 29 | "hits": [ 30 | { 31 | "_index": "ac_test3", 32 | "_type": "ac_test3", 33 | "_id": "3", 34 | "_score": 4.430304, 35 | "_source": { 36 | "item": "신혼가전특별전", 37 | "itemChosung": "신혼가전특별전" 38 | } 39 | }, 40 | { 41 | "_index": "ac_test3", 42 | "_type": "ac_test3", 43 | "_id": "2", 44 | "_score": 4.1501675, 45 | "_source": { 46 | "item": "신혼가전", 47 | "itemChosung": "신혼가전" 48 | } 49 | } 50 | ] 51 | } 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.3/7.3.3.4/02.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | GET /ac_test4/_search 3 | 4 | # 결과 5 | { 6 | "took": 2, 7 | "timed_out": false, 8 | "_shards": { 9 | "total": 5, 10 | "successful": 5, 11 | "skipped": 0, 12 | "failed": 0 13 | }, 14 | "hits": { 15 | "total": 3, 16 | "max_score": 1, 17 | "hits": [ 18 | { 19 | "_index": "ac_test4", 20 | "_type": "ac_test4", 21 | "_id": "2", 22 | "_score": 1, 23 | "_source": { 24 | "item": "신혼가전", 25 | "itemJamo": "신혼가전" 26 | } 27 | }, 28 | { 29 | "_index": "ac_test4", 30 | "_type": "ac_test4", 31 | "_id": "1", 32 | "_score": 1, 33 | "_source": { 34 | "item": "신혼", 35 | "itemJamo": "신혼" 36 | } 37 | }, 38 | { 39 | "_index": "ac_test4", 40 | "_type": "ac_test4", 41 | "_id": "3", 42 | "_score": 1, 43 | "_source": { 44 | "item": "신혼가전특별전", 45 | "itemJamo": "신혼가전특별전" 46 | } 47 | } 48 | ] 49 | } 50 | } 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /document/sample/chapter07/7.3/7.3.3.4/03.txt: -------------------------------------------------------------------------------- 1 | # 요청 2 | POST /ac_test4/_search 3 | { 4 | "query" : { 5 | "bool" : { 6 | "should" : [{ 7 | "term" : { 8 | "itemJamo" : "ㅅㅣㄴㅎ" 9 | } 10 | }], 11 | "minimum_should_match" : 1 12 | } 13 | } 14 | } 15 | 16 | # 결과 17 | { 18 | "took": 1, 19 | "timed_out": false, 20 | "_shards": { 21 | "total": 5, 22 | "successful": 5, 23 | "skipped": 0, 24 | "failed": 0 25 | }, 26 | "hits": { 27 | "total": 3, 28 | "max_score": 4.70558, 29 | "hits": [ 30 | { 31 | "_index": "ac_test4", 32 | "_type": "ac_test4", 33 | "_id": "3", 34 | "_score": 4.70558, 35 | "_source": { 36 | "item": "신혼가전특별전", 37 | "itemJamo": "신혼가전특별전" 38 | } 39 | }, 40 | { 41 | "_index": "ac_test4", 42 | "_type": "ac_test4", 43 | "_id": "2", 44 | "_score": 4.5802016, 45 | "_source": { 46 | "item": "신혼가전", 47 | "itemJamo": "신혼가전" 48 | } 49 | }, 50 | { 51 | "_index": "ac_test4", 52 | "_type": "ac_test4", 53 | "_id": "1", 54 | "_score": 4.3648314, 55 | "_source": { 56 | "item": "신혼", 57 | "itemJamo": "신혼" 58 | } 59 | } 60 | ] 61 | } 62 | } 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /document/system/cat/_cat.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat 2 | 3 | =^.^= 4 | /_cat/allocation 5 | /_cat/shards 6 | /_cat/shards/{index} 7 | /_cat/master 8 | /_cat/nodes 9 | /_cat/tasks 10 | /_cat/indices 11 | /_cat/indices/{index} 12 | /_cat/segments 13 | /_cat/segments/{index} 14 | /_cat/count 15 | /_cat/count/{index} 16 | /_cat/recovery 17 | /_cat/recovery/{index} 18 | /_cat/health 19 | /_cat/pending_tasks 20 | /_cat/aliases 21 | /_cat/aliases/{alias} 22 | /_cat/thread_pool 23 | /_cat/thread_pool/{thread_pools} 24 | /_cat/plugins 25 | /_cat/fielddata 26 | /_cat/fielddata/{fields} 27 | /_cat/nodeattrs 28 | /_cat/repositories 29 | /_cat/snapshots/{repository} 30 | /_cat/templates 31 | -------------------------------------------------------------------------------- /document/system/cat/_cat@allocation.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/allocation 2 | 3 | 40 128.2mb 5.4gb 23.5gb 29gb 18 10.0.0.4 10.0.0.4 data-node-02 4 | 40 131.8mb 5.4gb 23.5gb 29gb 18 10.0.0.4 10.0.0.4 data-node-01 5 | 40 138.4mb 5.4gb 23.5gb 29gb 18 10.0.0.4 10.0.0.4 data-node-03 6 | -------------------------------------------------------------------------------- /document/system/cat/_cat@count.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/count 2 | 3 | 1526285000 17:03:20 180157 4 | -------------------------------------------------------------------------------- /document/system/cat/_cat@fielddata.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/fielddata 2 | 3 | edrJa0eQR7-NJ10saIpgFg 10.0.0.4 10.0.0.4 data-node-02 genreAlt 2kb 4 | edrJa0eQR7-NJ10saIpgFg 10.0.0.4 10.0.0.4 data-node-02 nationAlt.keyword 7.5kb 5 | dYYuWMd9Sz-YDaMBKZaGFw 10.0.0.4 10.0.0.4 data-node-01 genreAlt 2.3kb 6 | dYYuWMd9Sz-YDaMBKZaGFw 10.0.0.4 10.0.0.4 data-node-01 nationAlt.keyword 9.9kb 7 | e6YYBK_6Su2qugjR0IfPZw 10.0.0.4 10.0.0.4 data-node-03 nationAlt.keyword 4.8kb 8 | e6YYBK_6Su2qugjR0IfPZw 10.0.0.4 10.0.0.4 data-node-03 genreAlt 1.1kb 9 | -------------------------------------------------------------------------------- /document/system/cat/_cat@health.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/health 2 | 3 | 1526285071 17:04:31 javacafe-es green 4 3 120 60 0 0 0 0 - 100.0% 4 | -------------------------------------------------------------------------------- /document/system/cat/_cat@indices.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/indices 2 | 3 | green open movie ZlrDB-TOR4GDKDe-C7yxPQ 5 1 30000 0 20.4mb 10.1mb 4 | green open test_analy Cm74TcGkRGSTnWsvM5-PzA 5 1 0 0 2.2kb 1.1kb 5 | green open my_index rNJ0NvbkTCmwIJhn9E-HFQ 5 1 1 0 8.4kb 4.2kb 6 | green open news a03YTpNtQUyMJAC-j1l2iA 5 1 20000 0 193mb 97.1mb 7 | green open animals fcUrX4NdRH2GlP-HvxPqZw 5 1 279 0 1.5mb 785.8kb 8 | green open movie_suggest 8FX3qb2ISJqmfK_u9pMaSQ 5 1 12 0 88.3kb 41.5kb 9 | green open stocks FaFBDtIGTvSsywwx0gmpvw 5 1 37286 0 48.5mb 24mb 10 | green open test_analzyer ZbMQ_Ov5TNy8NYYdSkbRaw 5 1 2 0 15.6kb 7.8kb 11 | green open testindex3 wUW_KdjdSxaV7MIFo_FVHg 5 1 1 0 17.8kb 8.9kb 12 | green open tweet qsZg67IdRGegGRIOY_ywMg 5 1 29507 0 46mb 22.9mb 13 | green open movie_autocomplete sIgm3NDLQdCfWlafue7Fuw 5 1 63069 0 88.8mb 45.3mb 14 | green open test_analyzer _dKASK5kRES91RkZ_38PPw 5 1 0 0 2.2kb 1.1kb 15 | -------------------------------------------------------------------------------- /document/system/cat/_cat@master.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/master 2 | 3 | T0eKC161SL6QFI3KtBFMog 10.0.0.4 10.0.0.4 master-node-01 4 | -------------------------------------------------------------------------------- /document/system/cat/_cat@nodes.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/nodes 2 | 3 | 10.0.0.4 32 84 2 0.01 0.02 0.00 di - data-node-03 4 | 10.0.0.4 33 84 2 0.01 0.02 0.00 di - data-node-01 5 | 10.0.0.4 68 84 2 0.01 0.02 0.00 mi * master-node-01 6 | 10.0.0.4 27 84 2 0.01 0.02 0.00 di - data-node-02 7 | -------------------------------------------------------------------------------- /document/system/cat/_cat@plugins.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/plugins 2 | 3 | data-node-03 analysis-seunjeon 6.1.1.1 4 | data-node-03 hangul-jamo-analyzer 1.0-SNAPSHOT 5 | data-node-01 analysis-seunjeon 6.1.1.1 6 | data-node-01 hangul-jamo-analyzer 1.0-SNAPSHOT 7 | master-node-01 analysis-seunjeon 6.1.1.1 8 | master-node-01 hangul-jamo-analyzer 1.0-SNAPSHOT 9 | data-node-02 analysis-seunjeon 6.1.1.1 10 | data-node-02 hangul-jamo-analyzer 1.0-SNAPSHOT 11 | -------------------------------------------------------------------------------- /document/system/cat/_cat@tasks.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/tasks 2 | 3 | cluster:monitor/tasks/lists T0eKC161SL6QFI3KtBFMog:33158642 - transport 1526284734645 16:58:54 14.9ms 10.0.0.4 master-node-01 4 | cluster:monitor/tasks/lists[n] dYYuWMd9Sz-YDaMBKZaGFw:9219143 T0eKC161SL6QFI3KtBFMog:33158642 netty 1526284734647 16:58:54 4.3ms 10.0.0.4 data-node-01 5 | cluster:monitor/tasks/lists[n] e6YYBK_6Su2qugjR0IfPZw:9056957 T0eKC161SL6QFI3KtBFMog:33158642 netty 1526284734647 16:58:54 4.3ms 10.0.0.4 data-node-03 6 | cluster:monitor/tasks/lists[n] T0eKC161SL6QFI3KtBFMog:33158643 T0eKC161SL6QFI3KtBFMog:33158642 direct 1526284734654 16:58:54 5.5ms 10.0.0.4 master-node-01 7 | cluster:monitor/tasks/lists[n] edrJa0eQR7-NJ10saIpgFg:9063114 T0eKC161SL6QFI3KtBFMog:33158642 netty 1526284734655 16:58:54 4.2ms 10.0.0.4 data-node-02 8 | -------------------------------------------------------------------------------- /document/system/cat/_cat@templates.txt: -------------------------------------------------------------------------------- 1 | http://elastic.javacafe.io:20010/_cat/templates 2 | 3 | logstash [logstash-*] 0 60001 4 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | io.javacafe.elastic 8 | elastic-book 9 | 1.0-SNAPSHOT 10 | 11 | 12 | elastic-lucene-snapshots 13 | Elastic Lucene Snapshots 14 | http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/00142c9 15 | true 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.elasticsearch.client 25 | transport 26 | 6.4.3 27 | 28 | 29 | 30 | 31 | org.elasticsearch.client 32 | elasticsearch-rest-high-level-client 33 | 6.4.3 34 | 35 | 36 | 37 | 38 | org.locationtech.spatial4j 39 | spatial4j 40 | 0.7 41 | 42 | 43 | 44 | org.locationtech.jts 45 | jts-core 46 | 1.15.0 47 | 48 | 49 | xerces 50 | xercesImpl 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example02.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.http.HttpHost; 6 | import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; 7 | import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; 8 | import org.elasticsearch.client.RequestOptions; 9 | import org.elasticsearch.client.RestClient; 10 | import org.elasticsearch.client.RestHighLevelClient; 11 | 12 | public class Example02 { 13 | /** 14 | * 인덱스 삭제 15 | * */ 16 | public static void main(String[] args) throws IOException { 17 | 18 | RestHighLevelClient client = new RestHighLevelClient( 19 | RestClient.builder( 20 | new HttpHost("127.0.0.1", 9200, "http"))); 21 | 22 | // Index명 23 | String INDEX_NAME = "movie_rest"; 24 | 25 | 26 | // 인덱스 삭제 27 | DeleteIndexRequest request = new DeleteIndexRequest(INDEX_NAME); 28 | 29 | DeleteIndexResponse deleteIndexResponse = 30 | client.indices().delete(request,RequestOptions.DEFAULT); 31 | 32 | boolean acknowledged = deleteIndexResponse.isAcknowledged(); 33 | 34 | client.close(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example03.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.http.HttpHost; 6 | import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; 7 | import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; 8 | import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; 9 | import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; 10 | import org.elasticsearch.client.RequestOptions; 11 | import org.elasticsearch.client.RestClient; 12 | import org.elasticsearch.client.RestHighLevelClient; 13 | 14 | public class Example03 { 15 | /** 16 | * 인덱스 오픈 및 종료 17 | * */ 18 | public static void main(String[] args) throws IOException { 19 | 20 | RestHighLevelClient client = new RestHighLevelClient( 21 | RestClient.builder( 22 | new HttpHost("127.0.0.1", 9200, "http"))); 23 | 24 | // Index명 25 | String INDEX_NAME = "movie_auto"; 26 | 27 | 28 | // Index Open 29 | OpenIndexRequest requestOpen = new OpenIndexRequest(INDEX_NAME); 30 | 31 | OpenIndexResponse openIndexResponse = 32 | client.indices().open(requestOpen, RequestOptions.DEFAULT); 33 | 34 | boolean ackOpen = openIndexResponse.isAcknowledged(); 35 | 36 | 37 | // Index Close 38 | CloseIndexRequest requestClose = new CloseIndexRequest(INDEX_NAME); 39 | 40 | CloseIndexResponse closeIndexResponse = 41 | client.indices().close(requestClose, RequestOptions.DEFAULT); 42 | 43 | boolean ackClose = closeIndexResponse.isAcknowledged(); 44 | 45 | client.close(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example04.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; 4 | 5 | import java.io.IOException; 6 | 7 | import org.apache.http.HttpHost; 8 | import org.elasticsearch.ElasticsearchException; 9 | import org.elasticsearch.action.index.IndexRequest; 10 | import org.elasticsearch.action.index.IndexResponse; 11 | import org.elasticsearch.client.RequestOptions; 12 | import org.elasticsearch.client.RestClient; 13 | import org.elasticsearch.client.RestHighLevelClient; 14 | import org.elasticsearch.rest.RestStatus; 15 | 16 | public class Example04 { 17 | /** 18 | * 인덱스 데이터 추가 19 | * */ 20 | public static void main(String[] args) throws IOException { 21 | 22 | RestHighLevelClient client = new RestHighLevelClient( 23 | RestClient.builder( 24 | new HttpHost("127.0.0.1", 9200, "http"))); 25 | 26 | // 인덱스 명 27 | String INDEX_NAME = "movie_auto_java"; 28 | 29 | // 타입 명 30 | String TYPE_NAME="_doc"; 31 | 32 | // 문서 키값 33 | String _id = "1"; 34 | 35 | 36 | // 데이터 추가 37 | IndexRequest request = new IndexRequest(INDEX_NAME,TYPE_NAME,_id); 38 | 39 | request.source(jsonBuilder() 40 | .startObject() 41 | .field("movieCd", "20173732") 42 | .field("movieNm", "살아남은 아이") 43 | .field("movieNmEn", "Last Child") 44 | .endObject() 45 | ); 46 | 47 | 48 | // 결과 조회 49 | try { 50 | IndexResponse response = client.index(request, RequestOptions.DEFAULT); 51 | 52 | } catch(ElasticsearchException e) { 53 | if (e.status() == RestStatus.CONFLICT) { 54 | System.out.println("문서 생성에 실패하였습니다."); 55 | } 56 | } 57 | 58 | client.close(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example05.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import org.apache.http.HttpHost; 4 | import org.elasticsearch.ElasticsearchException; 5 | import org.elasticsearch.action.get.GetRequest; 6 | import org.elasticsearch.action.get.GetResponse; 7 | import org.elasticsearch.action.index.IndexRequest; 8 | import org.elasticsearch.action.index.IndexResponse; 9 | import org.elasticsearch.client.RequestOptions; 10 | import org.elasticsearch.client.RestClient; 11 | import org.elasticsearch.client.RestHighLevelClient; 12 | import org.elasticsearch.rest.RestStatus; 13 | 14 | import java.io.IOException; 15 | import java.util.Map; 16 | 17 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; 18 | 19 | public class Example05 { 20 | /** 21 | * GET API 22 | * */ 23 | public static void main(String[] args) throws IOException { 24 | 25 | RestHighLevelClient client = new RestHighLevelClient( 26 | RestClient.builder( 27 | new HttpHost("127.0.0.1", 9200, "http"))); 28 | 29 | // 인덱스명 30 | String INDEX_NAME = "movie_auto_java"; 31 | 32 | // 타입명 33 | String TYPE_NAME="_doc"; 34 | 35 | // 문서 키값 36 | String _id = "1"; 37 | 38 | // 요청 39 | GetRequest request = new GetRequest( INDEX_NAME, TYPE_NAME, _id); 40 | 41 | // 응답 42 | GetResponse response = client.get(request, RequestOptions.DEFAULT); 43 | 44 | // 응답의 결과를 Map 형태로 제공받는다. 45 | if (response.isExists()) { 46 | long version = response.getVersion(); 47 | Map sourceAsMap = response.getSourceAsMap(); 48 | 49 | } else { 50 | System.out.println("결과가 존재하지 않습니다."); 51 | } 52 | 53 | client.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example06.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import org.apache.http.HttpHost; 4 | import org.elasticsearch.action.get.GetRequest; 5 | import org.elasticsearch.action.get.GetResponse; 6 | import org.elasticsearch.client.RequestOptions; 7 | import org.elasticsearch.client.RestClient; 8 | import org.elasticsearch.client.RestHighLevelClient; 9 | 10 | import java.io.IOException; 11 | import java.util.Map; 12 | 13 | public class Example06 { 14 | /** 15 | * Exists API 16 | * */ 17 | public static void main(String[] args) throws IOException { 18 | 19 | RestHighLevelClient client = new RestHighLevelClient( 20 | RestClient.builder( 21 | new HttpHost("127.0.0.1", 9200, "http"))); 22 | 23 | //인덱스 명 24 | String INDEX_NAME = "movie_auto_java"; 25 | 26 | //타입 명 27 | String TYPE_NAME="_doc"; 28 | 29 | //문서 키값 30 | String _id = "1"; 31 | 32 | GetRequest getRequest = new GetRequest( INDEX_NAME, TYPE_NAME, _id); 33 | boolean exists = client.exists(getRequest, RequestOptions.DEFAULT); 34 | 35 | client.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example07.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import org.apache.http.HttpHost; 4 | import org.elasticsearch.action.delete.DeleteRequest; 5 | import org.elasticsearch.action.delete.DeleteResponse; 6 | import org.elasticsearch.action.get.GetRequest; 7 | import org.elasticsearch.client.RequestOptions; 8 | import org.elasticsearch.client.RestClient; 9 | import org.elasticsearch.client.RestHighLevelClient; 10 | 11 | import java.io.IOException; 12 | 13 | public class Example07 { 14 | /** 15 | * DELETE API 16 | * */ 17 | public static void main(String[] args) throws IOException { 18 | 19 | RestHighLevelClient client = new RestHighLevelClient( 20 | RestClient.builder( 21 | new HttpHost("127.0.0.1", 9200, "http"))); 22 | 23 | //인덱스 명 24 | String INDEX_NAME = "movie_auto_java"; 25 | 26 | //타입 명 27 | String TYPE_NAME="_doc"; 28 | 29 | //문서 키값 30 | String _id = "1"; 31 | 32 | DeleteRequest request = new DeleteRequest(INDEX_NAME, TYPE_NAME, _id); 33 | DeleteResponse deleteResponse = client.delete(request, RequestOptions.DEFAULT); 34 | 35 | client.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example08A.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import static java.util.Collections.singletonMap; 4 | 5 | import java.io.IOException; 6 | import java.util.Map; 7 | 8 | import org.apache.http.HttpHost; 9 | import org.elasticsearch.ElasticsearchException; 10 | import org.elasticsearch.action.update.UpdateRequest; 11 | import org.elasticsearch.action.update.UpdateResponse; 12 | import org.elasticsearch.client.RequestOptions; 13 | import org.elasticsearch.client.RestClient; 14 | import org.elasticsearch.client.RestHighLevelClient; 15 | import org.elasticsearch.rest.RestStatus; 16 | import org.elasticsearch.script.Script; 17 | import org.elasticsearch.script.ScriptType; 18 | 19 | public class Example08A { 20 | /** 21 | * UPSERT API 22 | * */ 23 | public static void main(String[] args) throws IOException { 24 | 25 | RestHighLevelClient client = new RestHighLevelClient( 26 | RestClient.builder( 27 | new HttpHost("127.0.0.1", 9200, "http"))); 28 | 29 | // 인덱스명 30 | String INDEX_NAME = "movie_auto_java"; 31 | 32 | // 타입명 33 | String TYPE_NAME="_doc"; 34 | 35 | // 문서 키값 36 | String _id = "1"; 37 | 38 | 39 | /** 40 | * [업데이트 요청1] 41 | * 42 | * 스크립트를 이용한 업데이트 방식 43 | */ 44 | UpdateRequest request1 = new UpdateRequest(INDEX_NAME, TYPE_NAME, _id); 45 | 46 | Map parameters = singletonMap("count", 10); 47 | Script inline = 48 | new Script(ScriptType.INLINE, "painless", "ctx._source.prdtYear += params.count", parameters); 49 | 50 | request1.script(inline); 51 | 52 | try { 53 | UpdateResponse updateResponse = client.update(request1, RequestOptions.DEFAULT); 54 | } catch (ElasticsearchException e) { 55 | if (e.status() == RestStatus.NOT_FOUND) { 56 | System.out.println("업데이트 대상이 존재하지 않습니다."); 57 | } 58 | } 59 | 60 | 61 | 62 | 63 | client.close(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example08B.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; 4 | 5 | import java.io.IOException; 6 | import java.util.Date; 7 | 8 | import org.apache.http.HttpHost; 9 | import org.elasticsearch.ElasticsearchException; 10 | import org.elasticsearch.action.update.UpdateRequest; 11 | import org.elasticsearch.action.update.UpdateResponse; 12 | import org.elasticsearch.client.RequestOptions; 13 | import org.elasticsearch.client.RestClient; 14 | import org.elasticsearch.client.RestHighLevelClient; 15 | import org.elasticsearch.common.xcontent.XContentBuilder; 16 | import org.elasticsearch.rest.RestStatus; 17 | 18 | public class Example08B { 19 | /** 20 | * UPSERT API 21 | * */ 22 | public static void main(String[] args) throws IOException { 23 | 24 | RestHighLevelClient client = new RestHighLevelClient( 25 | RestClient.builder( 26 | new HttpHost("127.0.0.1", 9200, "http"))); 27 | 28 | // 인덱스명 29 | String INDEX_NAME = "movie_auto_java"; 30 | 31 | // 타입명 32 | String TYPE_NAME="_doc"; 33 | 34 | // 문서 키값 35 | String _id = "1"; 36 | 37 | 38 | /** 39 | * [업데이트 요청2] 40 | * 41 | * 문서의 부분을 업데이트 방식 42 | */ 43 | XContentBuilder builder = jsonBuilder(); 44 | builder.startObject(); 45 | builder.field("createdAt", new Date()); 46 | builder.field("prdtYear", "2019"); 47 | builder.field("typeNm", "장편"); 48 | builder.endObject(); 49 | 50 | UpdateRequest request2 = new UpdateRequest(INDEX_NAME, TYPE_NAME, _id).doc(builder); 51 | 52 | try { 53 | UpdateResponse updateResponse = client.update(request2, RequestOptions.DEFAULT); 54 | } catch (ElasticsearchException e) { 55 | if (e.status() == RestStatus.NOT_FOUND) { 56 | System.out.println("업데이트 대상이 존재하지 않습니다."); 57 | } 58 | } 59 | 60 | 61 | client.close(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example11.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import java.io.IOException; 4 | import java.util.Map; 5 | 6 | import org.apache.http.HttpHost; 7 | import org.elasticsearch.action.search.SearchRequest; 8 | import org.elasticsearch.action.search.SearchResponse; 9 | import org.elasticsearch.client.RequestOptions; 10 | import org.elasticsearch.client.RestClient; 11 | import org.elasticsearch.client.RestHighLevelClient; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.search.SearchHit; 14 | import org.elasticsearch.search.SearchHits; 15 | import org.elasticsearch.search.builder.SearchSourceBuilder; 16 | import org.elasticsearch.search.sort.FieldSortBuilder; 17 | import org.elasticsearch.search.sort.SortOrder; 18 | 19 | public class Example11 { 20 | /** 21 | * Match ALL API 22 | * */ 23 | public static void main(String[] args) throws IOException { 24 | 25 | RestHighLevelClient client = new RestHighLevelClient( 26 | RestClient.builder( 27 | new HttpHost("127.0.0.1", 9200, "http"))); 28 | 29 | // 인덱스명 30 | String INDEX_NAME = "movie_auto_java"; 31 | 32 | // 타입명 33 | String TYPE_NAME="_doc"; 34 | 35 | // 필드명 36 | String FIELD_NAME = "movieNm"; 37 | 38 | 39 | // 검색 쿼리 설정 40 | SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 41 | 42 | searchSourceBuilder.query(QueryBuilders.matchAllQuery()); 43 | searchSourceBuilder.from(0); 44 | searchSourceBuilder.size(5); 45 | searchSourceBuilder.sort(new FieldSortBuilder(FIELD_NAME).order(SortOrder.DESC)); 46 | 47 | 48 | // 요청 49 | SearchRequest searchRequest = new SearchRequest(INDEX_NAME); 50 | searchRequest.types(TYPE_NAME); 51 | searchRequest.source(searchSourceBuilder); 52 | 53 | 54 | // 응답 55 | SearchResponse searchResponse = client.search(searchRequest,RequestOptions.DEFAULT); 56 | SearchHits searchHits = searchResponse.getHits(); 57 | for (SearchHit hit : searchHits) { 58 | Map sourceAsMap = hit.getSourceAsMap(); 59 | } 60 | 61 | client.close(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example13.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import org.apache.http.HttpHost; 4 | import org.elasticsearch.action.search.ClearScrollRequest; 5 | import org.elasticsearch.action.search.ClearScrollResponse; 6 | import org.elasticsearch.action.search.SearchRequest; 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.client.RequestOptions; 9 | import org.elasticsearch.client.RestClient; 10 | import org.elasticsearch.client.RestHighLevelClient; 11 | import org.elasticsearch.common.unit.TimeValue; 12 | import org.elasticsearch.search.builder.SearchSourceBuilder; 13 | 14 | import java.io.IOException; 15 | 16 | import static org.elasticsearch.index.query.QueryBuilders.matchQuery; 17 | /** 18 | * CLEAR SCROLL API 19 | * */ 20 | public class Example13 { 21 | public static void main(String[] args) throws IOException { 22 | 23 | RestHighLevelClient client = new RestHighLevelClient( 24 | RestClient.builder( 25 | new HttpHost("127.0.0.1", 9200, "http"))); 26 | 27 | 28 | String INDEX_NAME = "movie_auto_java"; 29 | String FIELD_NAME = "movieNm"; 30 | String QUERY_TEXT = "캡틴아메리카"; 31 | 32 | SearchRequest searchRequest = new SearchRequest(INDEX_NAME); 33 | 34 | SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); 35 | searchSourceBuilder.query(matchQuery(FIELD_NAME, QUERY_TEXT)); 36 | searchRequest.source(searchSourceBuilder); 37 | 38 | searchRequest.scroll (TimeValue.timeValueMinutes (1L)); 39 | 40 | SearchResponse searchResponse = client.search(searchRequest,RequestOptions.DEFAULT); 41 | String scrollId = searchResponse.getScrollId(); 42 | 43 | ClearScrollRequest request = new ClearScrollRequest(); 44 | request.addScrollId(scrollId); 45 | //scroll ID가 여러개일 경우는 setScrollIds를 사용하여 조회 가능 46 | //request.setScrollIds(scrollIds); 47 | ClearScrollResponse response = client.clearScroll(request, RequestOptions.DEFAULT); 48 | 49 | //해당 scrollId가 정상적으로 release 되었는지 확인 가능 50 | boolean success = response.isSucceeded(); 51 | int released = response.getNumFreed(); 52 | 53 | client.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/rest/Example14.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.rest; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.apache.http.HttpHost; 8 | import org.elasticsearch.action.search.SearchRequest; 9 | import org.elasticsearch.action.search.SearchResponse; 10 | import org.elasticsearch.client.RequestOptions; 11 | import org.elasticsearch.client.RestClient; 12 | import org.elasticsearch.client.RestHighLevelClient; 13 | import org.elasticsearch.script.ScriptType; 14 | import org.elasticsearch.script.mustache.SearchTemplateRequest; 15 | import org.elasticsearch.script.mustache.SearchTemplateResponse; 16 | 17 | 18 | /** 19 | * Search Template API 20 | * */ 21 | public class Example14 { 22 | public static void main(String[] args) throws IOException { 23 | 24 | RestHighLevelClient client = new RestHighLevelClient( 25 | RestClient.builder( 26 | new HttpHost("127.0.0.1", 9200, "http"))); 27 | 28 | String INDEX_NAME = "movie_auto_java"; 29 | String FIELD_NAME = "movieNm"; 30 | String QUERY_TEXT = "캡틴아메리카"; 31 | 32 | SearchTemplateRequest searchRequest = new SearchTemplateRequest(); 33 | searchRequest.setRequest(new SearchRequest(INDEX_NAME)); 34 | 35 | searchRequest.setScriptType(ScriptType.INLINE); 36 | searchRequest.setScript( 37 | "{" + 38 | " \"query\": { \"match\" : { \"{{field}}\" : \"{{value}}\" } }," + 39 | " \"size\" : \"{{size}}\"" + 40 | "}"); 41 | 42 | Map scriptParams = new HashMap<>(); 43 | scriptParams.put("field", FIELD_NAME); 44 | scriptParams.put("value", QUERY_TEXT); 45 | scriptParams.put("size", 10); 46 | searchRequest.setScriptParams(scriptParams); 47 | 48 | SearchTemplateResponse searchTemplateResponse = client.searchTemplate(searchRequest, RequestOptions.DEFAULT); 49 | SearchResponse response = searchTemplateResponse.getResponse(); 50 | 51 | 52 | client.close(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example01.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import org.elasticsearch.client.transport.TransportClient; 4 | import org.elasticsearch.common.settings.Settings; 5 | import org.elasticsearch.common.transport.TransportAddress; 6 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 7 | 8 | import java.net.InetAddress; 9 | import java.net.UnknownHostException; 10 | 11 | 12 | /** 13 | * Transport 연결 14 | * 15 | * @author User 16 | * 17 | */ 18 | public class Example01 { 19 | 20 | @SuppressWarnings({ "resource", "unchecked" }) 21 | public static void main(String[] args) throws UnknownHostException { 22 | 23 | 24 | Settings settings = Settings.builder() .put("cluster.name", "elasticsearch").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | 31 | client.close(); 32 | 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example04.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | 8 | import org.elasticsearch.action.index.IndexResponse; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 13 | 14 | /** 15 | * 하나의 문서 추가 16 | * 17 | * @author User 18 | * 19 | */ 20 | public class Example04 { 21 | 22 | 23 | @SuppressWarnings({ "resource", "unchecked" }) 24 | public static void main(String[] args) throws IOException { 25 | 26 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 27 | 28 | TransportClient client = 29 | new PreBuiltTransportClient(settings) 30 | .addTransportAddress(new TransportAddress( 31 | InetAddress.getByName("127.0.0.1"), 9300)); 32 | 33 | // Index명 34 | String INDEX_NAME="movie_auto_java"; 35 | 36 | // 타입명 37 | String TYPE_NAME = "_doc"; 38 | 39 | // 문서 키값 40 | String _id = "1"; 41 | 42 | 43 | IndexResponse response = client.prepareIndex(INDEX_NAME, TYPE_NAME, _id) 44 | .setSource(jsonBuilder() 45 | .startObject() 46 | .field("movieCd", "20173732") 47 | .field("movieNm", "살아남은 아이") 48 | .field("movieNmEn", "Last Child") 49 | .endObject()) 50 | .get(); 51 | 52 | 53 | client.close(); 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example06.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | 6 | import org.elasticsearch.action.get.GetResponse; 7 | import org.elasticsearch.client.transport.TransportClient; 8 | import org.elasticsearch.common.settings.Settings; 9 | import org.elasticsearch.common.transport.TransportAddress; 10 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 11 | 12 | /** 13 | * 하나의 문서 조회 14 | * 15 | * @author User 16 | * 17 | */ 18 | public class Example06 { 19 | 20 | 21 | @SuppressWarnings({ "resource", "unchecked" }) 22 | public static void main(String[] args) throws IOException { 23 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 24 | 25 | TransportClient client = 26 | new PreBuiltTransportClient(settings) 27 | .addTransportAddress(new TransportAddress( 28 | InetAddress.getByName("127.0.0.1"), 9300)); 29 | 30 | //Index명 31 | String INDEX_NAME="movie_auto_java"; 32 | 33 | //타입명 34 | String TYPE_NAME = "_doc"; 35 | 36 | //문서 키값 37 | String _id = "20184623"; 38 | 39 | GetResponse response = client.prepareGet(INDEX_NAME, TYPE_NAME, _id).get(); 40 | 41 | client.close(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example07.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | 6 | import org.elasticsearch.action.delete.DeleteResponse; 7 | import org.elasticsearch.client.transport.TransportClient; 8 | import org.elasticsearch.common.settings.Settings; 9 | import org.elasticsearch.common.transport.TransportAddress; 10 | import org.elasticsearch.index.query.QueryBuilders; 11 | import org.elasticsearch.index.reindex.BulkByScrollResponse; 12 | import org.elasticsearch.index.reindex.DeleteByQueryAction; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * 하나 / 여러개의 문서 삭제 17 | * 18 | * @author User 19 | * 20 | */ 21 | public class Example07 { 22 | 23 | 24 | @SuppressWarnings({ "resource", "unchecked" }) 25 | public static void main(String[] args) throws IOException { 26 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 27 | 28 | TransportClient client = 29 | new PreBuiltTransportClient(settings) 30 | .addTransportAddress(new TransportAddress( 31 | InetAddress.getByName("127.0.0.1"), 9300)); 32 | 33 | //Index명 34 | String INDEX_NAME="movie_auto_java"; 35 | 36 | //타입명 37 | String TYPE_NAME = "_doc"; 38 | 39 | 40 | // 한건의 문서 삭제 41 | String _id = "20184623"; 42 | DeleteResponse response = client.prepareDelete(INDEX_NAME, TYPE_NAME, _id).get(); 43 | 44 | 45 | // 여러건의 문서 삭제 46 | BulkByScrollResponse bulkByScrollResponse = DeleteByQueryAction.INSTANCE.newRequestBuilder(client) 47 | .filter(QueryBuilders.matchQuery("movieNm", "바람난 아내들2")) 48 | .source(INDEX_NAME) 49 | .get(); 50 | 51 | long deleted = bulkByScrollResponse.getDeleted(); 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example08.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | import java.util.concurrent.ExecutionException; 8 | 9 | import org.elasticsearch.action.update.UpdateRequest; 10 | import org.elasticsearch.client.transport.TransportClient; 11 | import org.elasticsearch.common.settings.Settings; 12 | import org.elasticsearch.common.transport.TransportAddress; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * 문서 수정 17 | * 18 | * @author User 19 | * 20 | */ 21 | public class Example08 { 22 | 23 | 24 | @SuppressWarnings({ "resource", "unchecked" }) 25 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 26 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 27 | 28 | TransportClient client = 29 | new PreBuiltTransportClient(settings) 30 | .addTransportAddress(new TransportAddress( 31 | InetAddress.getByName("127.0.0.1"), 9300)); 32 | 33 | //Index명 34 | String INDEX_NAME="movie_auto_java"; 35 | 36 | //타입명 37 | String TYPE_NAME = "_doc"; 38 | 39 | // 한건의 문서 수정 40 | String _id = "20174244"; 41 | UpdateRequest updateRequest = new UpdateRequest(INDEX_NAME, TYPE_NAME, _id) 42 | .doc(jsonBuilder() 43 | .startObject() 44 | .field("movieNm", "수정 문서") 45 | .endObject()); 46 | 47 | client.update(updateRequest).get(); 48 | 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example09.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.get.GetResponse; 8 | import org.elasticsearch.action.get.MultiGetItemResponse; 9 | import org.elasticsearch.action.get.MultiGetResponse; 10 | import org.elasticsearch.client.transport.TransportClient; 11 | import org.elasticsearch.common.settings.Settings; 12 | import org.elasticsearch.common.transport.TransportAddress; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * 여러개의 검색 요청 17 | * 18 | * @author User 19 | * 20 | */ 21 | public class Example09 { 22 | 23 | 24 | @SuppressWarnings({ "resource", "unchecked" }) 25 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 26 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 27 | 28 | TransportClient client = 29 | new PreBuiltTransportClient(settings) 30 | .addTransportAddress(new TransportAddress( 31 | InetAddress.getByName("127.0.0.1"), 9300)); 32 | //Index명 33 | String INDEX_NAME="movie_auto_java"; 34 | 35 | //타입명 36 | String TYPE_NAME = "_doc"; 37 | 38 | MultiGetResponse multiGetItemResponses = client.prepareMultiGet() 39 | .add(INDEX_NAME, TYPE_NAME, "20184623") 40 | .add(INDEX_NAME, TYPE_NAME, "20174244") 41 | .get(); 42 | 43 | for (MultiGetItemResponse itemResponse : multiGetItemResponses) { 44 | GetResponse response1 = itemResponse.getResponse(); 45 | if (response1.isExists()) { 46 | String json = response1.getSourceAsString(); 47 | } 48 | } 49 | 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example11.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.action.search.SearchType; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * 쿼리 문서 조회 17 | * 18 | * @author User 19 | * 20 | */ 21 | public class Example11 { 22 | 23 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 24 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | 31 | String INDEX_NAME1 = "movie_auto"; 32 | String INDEX_NAME2 = "movie_search"; 33 | String TYPE_NAME = "_doc"; 34 | String FIELD_NAME = "movieCd"; 35 | String QUERY = "20184623"; 36 | 37 | SearchResponse response = client.prepareSearch(INDEX_NAME1, INDEX_NAME2) 38 | .setTypes(TYPE_NAME) 39 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 40 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 41 | .setFrom(0).setSize(10) 42 | .setExplain(true) 43 | .get(); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example14.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.action.search.SearchType; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.search.aggregations.AggregationBuilders; 14 | import org.elasticsearch.search.aggregations.metrics.min.Min; 15 | import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; 16 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 17 | 18 | public class Example14 { 19 | 20 | 21 | /** 22 | * MIN Aggregation 사용하기 23 | * */ 24 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 25 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 26 | 27 | TransportClient client = 28 | new PreBuiltTransportClient(settings) 29 | .addTransportAddress(new TransportAddress( 30 | InetAddress.getByName("127.0.0.1"), 9300)); 31 | 32 | String INDEX_NAME = "movie_search"; 33 | String TYPE_NAME = "_doc"; 34 | String FIELD_NAME = "repNationNm"; 35 | String QUERY = "한국"; 36 | 37 | String AGGREGATION_NAME = "MIN_AGG_NM"; 38 | String AGGREGATION_FIELD = "movieCd"; 39 | 40 | MinAggregationBuilder aggs = AggregationBuilders.min(AGGREGATION_NAME) 41 | .field(AGGREGATION_FIELD); 42 | 43 | 44 | // 검색 결과를 Aggregation한다. 45 | SearchResponse response = client.prepareSearch(INDEX_NAME) 46 | .setTypes(TYPE_NAME) 47 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 48 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 49 | .addAggregation(aggs) 50 | .setSize(0) 51 | .get(); 52 | 53 | //결과 출력 54 | Min minAgg = response.getAggregations().get(AGGREGATION_NAME); 55 | double value = minAgg.getValue(); 56 | 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example15.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.action.search.SearchType; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.search.aggregations.AggregationBuilders; 14 | import org.elasticsearch.search.aggregations.metrics.max.Max; 15 | import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; 16 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 17 | 18 | public class Example15 { 19 | 20 | /** 21 | * MAX Aggregation 사용하기 22 | * */ 23 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 24 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | String INDEX_NAME = "movie_search"; 31 | String TYPE_NAME = "_doc"; 32 | String FIELD_NAME = "repNationNm"; 33 | String QUERY = "한국"; 34 | 35 | String AGGREGATION_NAME = "MAX_AGG_NM"; 36 | String AGG_FIELD_NAME = "movieCd"; 37 | MaxAggregationBuilder aggregation = AggregationBuilders.max(AGGREGATION_NAME) 38 | .field(AGG_FIELD_NAME); 39 | 40 | //Aggregation으로 출력할 결과물을 addAggregation메소드에 담아 출력한다. 41 | SearchResponse response = client.prepareSearch(INDEX_NAME) 42 | .setTypes(TYPE_NAME) 43 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 44 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 45 | .addAggregation(aggregation) 46 | .setSize(0) 47 | .get(); 48 | 49 | //결과 출력 50 | Max maxAgg = response.getAggregations().get(AGGREGATION_NAME); 51 | double value = maxAgg.getValue(); 52 | ; 53 | 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example16.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.action.search.SearchType; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.search.aggregations.AggregationBuilders; 14 | import org.elasticsearch.search.aggregations.metrics.sum.Sum; 15 | import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder; 16 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 17 | 18 | public class Example16 { 19 | 20 | /** 21 | * SUM Aggregation 사용하기 22 | * */ 23 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 24 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | String INDEX_NAME = "movie_search"; 31 | String TYPE_NAME = "_doc"; 32 | String FIELD_NAME = "repNationNm"; 33 | String QUERY = "한국"; 34 | 35 | String AGGREGATION_NAME = "SUM_AGG_NM"; 36 | String AGG_FIELD_NAME = "movieCd"; 37 | SumAggregationBuilder aggregation = AggregationBuilders.sum(AGGREGATION_NAME) 38 | .field(AGG_FIELD_NAME); 39 | 40 | 41 | //Aggregation으로 출력할 결과물을 addAggregation메소드에 담아 출력한다. 42 | SearchResponse response = client.prepareSearch(INDEX_NAME) 43 | .setTypes(TYPE_NAME) 44 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 45 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 46 | .addAggregation(aggregation) 47 | .setSize(0) 48 | .get(); 49 | 50 | //결과 출력 51 | Sum sumAgg = response.getAggregations().get(AGGREGATION_NAME); 52 | double value = sumAgg.getValue(); 53 | 54 | 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example17.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.action.search.SearchType; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.search.aggregations.AggregationBuilders; 14 | import org.elasticsearch.search.aggregations.metrics.avg.Avg; 15 | import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder; 16 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 17 | 18 | public class Example17 { 19 | 20 | /** 21 | * AVG Aggregation 사용하기 22 | * */ 23 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 24 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | String INDEX_NAME = "movie_search"; 31 | String TYPE_NAME = "_doc"; 32 | String FIELD_NAME = "repNationNm"; 33 | String QUERY = "한국"; 34 | 35 | String AGGREGATION_NAME = "AVG_AGG_NM"; 36 | String AGG_FIELD_NAME = "movieCd"; 37 | AvgAggregationBuilder aggregation = AggregationBuilders.avg(AGGREGATION_NAME) 38 | .field(AGG_FIELD_NAME); 39 | 40 | 41 | //Aggregation으로 출력할 결과물을 addAggregation메소드에 담아 출력한다. 42 | SearchResponse response = client.prepareSearch(INDEX_NAME) 43 | .setTypes(TYPE_NAME) 44 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 45 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 46 | .addAggregation(aggregation) 47 | .setSize(0) 48 | .get(); 49 | 50 | //결과 출력 51 | Avg avgAgg = response.getAggregations().get(AGGREGATION_NAME); 52 | double value = avgAgg.getValue(); 53 | 54 | 55 | 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example21.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.action.search.SearchType; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.search.aggregations.AggregationBuilder; 14 | import org.elasticsearch.search.aggregations.AggregationBuilders; 15 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 16 | 17 | public class Example21 { 18 | 19 | /** 20 | * Term Aggregation 사용하기 21 | * */ 22 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 23 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 24 | 25 | TransportClient client = 26 | new PreBuiltTransportClient(settings) 27 | .addTransportAddress(new TransportAddress( 28 | InetAddress.getByName("127.0.0.1"), 9300)); 29 | String INDEX_NAME = "movie_search"; 30 | String TYPE_NAME = "_doc"; 31 | String FIELD_NAME = "repNationNm"; 32 | String QUERY = "한국"; 33 | 34 | String AGGREGATION_FIELD_FOR_USER = "repGenreNm"; 35 | AggregationBuilder aggs = AggregationBuilders.terms(AGGREGATION_FIELD_FOR_USER) 36 | .field(AGGREGATION_FIELD_FOR_USER ) 37 | .size(10); 38 | 39 | SearchResponse response = client.prepareSearch(INDEX_NAME) 40 | .setTypes(TYPE_NAME) 41 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 42 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 43 | .addAggregation(aggs) 44 | .setSize(0) 45 | .get(); 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example23.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.action.search.SearchType; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.search.aggregations.AggregationBuilder; 14 | import org.elasticsearch.search.aggregations.AggregationBuilders; 15 | import org.elasticsearch.search.aggregations.bucket.filter.Filter; 16 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 17 | 18 | public class Example23 { 19 | 20 | /** 21 | * Term Aggregation 사용하기 22 | * */ 23 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 24 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | String INDEX_NAME = "movie_search"; 31 | String TYPE_NAME = "_doc"; 32 | String FIELD_NAME = "repNationNm"; 33 | String QUERY = "한국"; 34 | 35 | 36 | String AGGREGATION_NAME="movie_aggregation"; 37 | String AGGREGATION_FIELD = "movieNmEn"; 38 | 39 | AggregationBuilder aggs = AggregationBuilders 40 | .missing(AGGREGATION_NAME).field(AGGREGATION_FIELD); 41 | 42 | SearchResponse response = client.prepareSearch(INDEX_NAME) 43 | .setTypes(TYPE_NAME) 44 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 45 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 46 | .addAggregation(aggs) 47 | .setSize(0) 48 | .get(); 49 | 50 | Filter agg = response.getAggregations().get(AGGREGATION_NAME); 51 | Long documentCount = agg.getDocCount(); 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example24.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.action.search.SearchType; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.Settings; 11 | import org.elasticsearch.common.transport.TransportAddress; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.search.aggregations.AggregationBuilder; 14 | import org.elasticsearch.search.aggregations.AggregationBuilders; 15 | import org.elasticsearch.search.aggregations.bucket.nested.Nested; 16 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 17 | 18 | public class Example24 { 19 | 20 | /** 21 | * nested Aggregation 사용하기 22 | * */ 23 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 24 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | String INDEX_NAME = "movie_search"; 31 | String TYPE_NAME = "_doc"; 32 | String FIELD_NAME = "repNationNm"; 33 | String QUERY = "한국"; 34 | 35 | String AGGREGATION_NAME="nested_aggregation"; 36 | String AGGREGATION_FIELD = "companies_nested"; 37 | 38 | AggregationBuilder aggs = AggregationBuilders 39 | .nested(AGGREGATION_NAME, AGGREGATION_FIELD); 40 | 41 | 42 | SearchResponse response = client.prepareSearch(INDEX_NAME) 43 | .setTypes(TYPE_NAME) 44 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 45 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 46 | .addAggregation(aggs) 47 | .setSize(0) 48 | .get(); 49 | 50 | Nested agg = response.getAggregations().get(AGGREGATION_NAME); 51 | Long documentCount = agg.getDocCount(); 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example26.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.client.transport.TransportClient; 9 | import org.elasticsearch.common.settings.Settings; 10 | import org.elasticsearch.common.transport.TransportAddress; 11 | import org.elasticsearch.index.query.QueryBuilders; 12 | import org.elasticsearch.search.aggregations.AggregationBuilder; 13 | import org.elasticsearch.search.aggregations.AggregationBuilders; 14 | import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms; 15 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 16 | 17 | public class Example26 { 18 | 19 | /** 20 | * Significant Aggregation 사용하기 21 | * */ 22 | 23 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 24 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | 31 | String INDEX_NAME = "movie_search"; 32 | String TYPE_NAME = "_doc"; 33 | String FIELD_NAME = "repNationNm"; 34 | String QUERY = "한국"; 35 | 36 | String AGGREGATION_NAME="significant_aggregation"; 37 | String AGGREGATION_FIELD = "typeNm"; 38 | 39 | 40 | AggregationBuilder aggregation = 41 | AggregationBuilders 42 | .significantTerms(AGGREGATION_NAME) 43 | .field(AGGREGATION_FIELD); 44 | 45 | SearchResponse sr = client.prepareSearch() 46 | .setQuery(QueryBuilders.termQuery(FIELD_NAME, QUERY)) 47 | .addAggregation(aggregation) 48 | .get(); 49 | SignificantTerms agg = sr.getAggregations().get(AGGREGATION_NAME); 50 | 51 | for (SignificantTerms.Bucket entry : agg.getBuckets()) { 52 | String typeNm = (String) entry.getKey(); // Term 53 | Long typeNmCount = entry.getDocCount(); // Doc count 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example28.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.client.transport.TransportClient; 9 | import org.elasticsearch.common.settings.Settings; 10 | import org.elasticsearch.common.transport.TransportAddress; 11 | import org.elasticsearch.index.query.QueryBuilder; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * MATCH ALL QUERY API 17 | * */ 18 | public class Example28 { 19 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 20 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 21 | 22 | TransportClient client = 23 | new PreBuiltTransportClient(settings) 24 | .addTransportAddress(new TransportAddress( 25 | InetAddress.getByName("127.0.0.1"), 9300)); 26 | String INDEX_NAME = "movie_search"; 27 | 28 | QueryBuilder queryBuilder = QueryBuilders.matchAllQuery(); 29 | SearchResponse scrollResp = client.prepareSearch(INDEX_NAME) 30 | .setQuery(queryBuilder) 31 | .setSize(30).get(); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example29.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.client.transport.TransportClient; 9 | import org.elasticsearch.common.settings.Settings; 10 | import org.elasticsearch.common.transport.TransportAddress; 11 | import org.elasticsearch.index.query.QueryBuilder; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * MATCH QUERY API 17 | * */ 18 | public class Example29 { 19 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 20 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 21 | 22 | TransportClient client = 23 | new PreBuiltTransportClient(settings) 24 | .addTransportAddress(new TransportAddress( 25 | InetAddress.getByName("127.0.0.1"), 9300)); 26 | 27 | String INDEX_NAME = "movie_search"; 28 | String FIELD_NAME = "movieNm"; 29 | String QUERY_KEYWORD = "아이"; 30 | 31 | QueryBuilder queryBuilder = QueryBuilders.matchQuery(FIELD_NAME, QUERY_KEYWORD); 32 | 33 | SearchResponse response = client.prepareSearch(INDEX_NAME) 34 | .setQuery(queryBuilder) 35 | .setSize(30) 36 | .get(); 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example30.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.client.transport.TransportClient; 9 | import org.elasticsearch.common.settings.Settings; 10 | import org.elasticsearch.common.transport.TransportAddress; 11 | import org.elasticsearch.index.query.QueryBuilder; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * MATCH QUERY API 17 | * */ 18 | public class Example30 { 19 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 20 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 21 | 22 | TransportClient client = 23 | new PreBuiltTransportClient(settings) 24 | .addTransportAddress(new TransportAddress( 25 | InetAddress.getByName("127.0.0.1"), 9300)); 26 | String INDEX_NAME = "movie_search"; 27 | String FIELD_NAME = "movieNm"; 28 | 29 | //Family in the Bubble 검색 30 | String QUERY_KEYWORD = "Family"; 31 | QueryBuilder queryBuilder = QueryBuilders.commonTermsQuery(FIELD_NAME, QUERY_KEYWORD); 32 | SearchResponse response = client.prepareSearch(INDEX_NAME) 33 | .setQuery(queryBuilder) 34 | .setSize(30).get(); 35 | 36 | 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example31.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.client.transport.TransportClient; 9 | import org.elasticsearch.common.settings.Settings; 10 | import org.elasticsearch.common.transport.TransportAddress; 11 | import org.elasticsearch.index.query.QueryBuilder; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * QUERY STRING API 17 | * */ 18 | public class Example31 { 19 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 20 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 21 | 22 | TransportClient client = 23 | new PreBuiltTransportClient(settings) 24 | .addTransportAddress(new TransportAddress( 25 | InetAddress.getByName("127.0.0.1"), 9300)); 26 | String INDEX_NAME = "movie_search"; 27 | String FIELD_NAME = "movieNm"; 28 | String QUERY_KEYWORD = "버블 OR 하이"; 29 | 30 | QueryBuilder queryBuilder = QueryBuilders.queryStringQuery(QUERY_KEYWORD).field(FIELD_NAME); 31 | SearchResponse response = client.prepareSearch(INDEX_NAME) 32 | .setQuery(queryBuilder) 33 | .setSize(30).get(); 34 | 35 | 36 | QUERY_KEYWORD = "+버블 -하이"; 37 | queryBuilder = QueryBuilders.queryStringQuery(QUERY_KEYWORD).field(FIELD_NAME); 38 | response = client.prepareSearch(INDEX_NAME) 39 | .setQuery(queryBuilder) 40 | .setSize(30).get(); 41 | 42 | 43 | 44 | 45 | 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example32.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.client.transport.TransportClient; 9 | import org.elasticsearch.common.settings.Settings; 10 | import org.elasticsearch.common.transport.TransportAddress; 11 | import org.elasticsearch.index.query.QueryBuilder; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * TERM QUERY API 17 | * */ 18 | public class Example32 { 19 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 20 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 21 | 22 | TransportClient client = 23 | new PreBuiltTransportClient(settings) 24 | .addTransportAddress(new TransportAddress( 25 | InetAddress.getByName("127.0.0.1"), 9300)); 26 | String INDEX_NAME = "movie_search"; 27 | String FIELD_NAME = "repNationNm"; 28 | String QUERY_KEYWORD = "한국"; 29 | 30 | QueryBuilder queryBuilder = QueryBuilders.termQuery(FIELD_NAME, QUERY_KEYWORD); 31 | SearchResponse response = client.prepareSearch(INDEX_NAME) 32 | .setQuery(queryBuilder) 33 | .setSize(30).get(); 34 | 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example33.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.elasticsearch.action.search.SearchResponse; 8 | import org.elasticsearch.client.transport.TransportClient; 9 | import org.elasticsearch.common.settings.Settings; 10 | import org.elasticsearch.common.transport.TransportAddress; 11 | import org.elasticsearch.index.query.QueryBuilder; 12 | import org.elasticsearch.index.query.QueryBuilders; 13 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 14 | 15 | /** 16 | * WILDCARD QUERY API 17 | * */ 18 | public class Example33 { 19 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 20 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 21 | 22 | TransportClient client = 23 | new PreBuiltTransportClient(settings) 24 | .addTransportAddress(new TransportAddress( 25 | InetAddress.getByName("127.0.0.1"), 9300)); 26 | String INDEX_NAME = "movie_search"; 27 | String FIELD_NAME = "movieNmEn"; 28 | String QUERY_KEYWORD = "F?m*"; 29 | 30 | QueryBuilder queryBuilder = QueryBuilders.wildcardQuery(FIELD_NAME,QUERY_KEYWORD); 31 | SearchResponse response = client.prepareSearch(INDEX_NAME) 32 | .setQuery(queryBuilder) 33 | .setSize(30).get(); 34 | 35 | 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example34.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import static org.elasticsearch.index.query.QueryBuilders.termQuery; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | import java.util.concurrent.ExecutionException; 8 | 9 | import org.elasticsearch.action.search.SearchResponse; 10 | import org.elasticsearch.client.transport.TransportClient; 11 | import org.elasticsearch.common.settings.Settings; 12 | import org.elasticsearch.common.transport.TransportAddress; 13 | import org.elasticsearch.index.query.QueryBuilder; 14 | import org.elasticsearch.index.query.QueryBuilders; 15 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 16 | 17 | /** 18 | * BOOL QUERY API 19 | * */ 20 | public class Example34 { 21 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 22 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 23 | 24 | TransportClient client = 25 | new PreBuiltTransportClient(settings) 26 | .addTransportAddress(new TransportAddress( 27 | InetAddress.getByName("127.0.0.1"), 9300)); 28 | 29 | String INDEX_NAME = "movie_search"; 30 | String FIELD_NAME_MUST = "repNationNm"; 31 | String QUERY_KEYWORD_MUST = "한국"; 32 | 33 | String FIELD_NAME_MUST_NOT = "repGenreNm"; 34 | String QUERY_KEYWORD_MUST_NOT="드라마"; 35 | 36 | String FIELD_NAME_SHOULD = "prdtYear"; 37 | String QUERY_KEYWORD_SHOULD="2017"; 38 | 39 | String FIELD_NAME_FIELTER = "movieCd"; 40 | String QUERY_KEYWORD_FIELTER="20173732"; 41 | 42 | QueryBuilder queryBuilder = QueryBuilders 43 | .boolQuery() 44 | .must(termQuery(FIELD_NAME_MUST, QUERY_KEYWORD_MUST)) 45 | .mustNot(termQuery(FIELD_NAME_MUST_NOT, QUERY_KEYWORD_MUST_NOT)) 46 | .should(termQuery(FIELD_NAME_SHOULD, QUERY_KEYWORD_SHOULD)) 47 | .filter(termQuery(FIELD_NAME_FIELTER, QUERY_KEYWORD_FIELTER)); 48 | 49 | SearchResponse response = client.prepareSearch(INDEX_NAME) 50 | .setQuery(queryBuilder) 51 | .setSize(30).get(); 52 | 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example35.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import static org.elasticsearch.index.query.QueryBuilders.termQuery; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | import java.util.concurrent.ExecutionException; 8 | 9 | import org.elasticsearch.action.search.SearchResponse; 10 | import org.elasticsearch.client.transport.TransportClient; 11 | import org.elasticsearch.common.settings.Settings; 12 | import org.elasticsearch.common.transport.TransportAddress; 13 | import org.elasticsearch.index.query.QueryBuilder; 14 | import org.elasticsearch.index.query.QueryBuilders; 15 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 16 | 17 | /** 18 | * DISMAX QUERY API 19 | * */ 20 | public class Example35 { 21 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 22 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 23 | 24 | TransportClient client = 25 | new PreBuiltTransportClient(settings) 26 | .addTransportAddress(new TransportAddress( 27 | InetAddress.getByName("127.0.0.1"), 9300)); 28 | 29 | String INDEX_NAME = "movie_search"; 30 | 31 | String FIELD_NAME1 = "repNationNm"; 32 | String QUERY_KEYWORD1 = "한국"; 33 | 34 | String FIELD_NAME2 = "repGenreNm"; 35 | String QUERY_KEYWORD2="드라마"; 36 | 37 | QueryBuilder queryBuilder = QueryBuilders 38 | .disMaxQuery() 39 | .add(termQuery(FIELD_NAME1, QUERY_KEYWORD1)) 40 | .add(termQuery(FIELD_NAME2, QUERY_KEYWORD2)) 41 | .boost(1.5f) 42 | .tieBreaker(0.5f); 43 | 44 | SearchResponse response = client.prepareSearch(INDEX_NAME) 45 | .setQuery(queryBuilder) 46 | .setSize(30).get(); 47 | 48 | 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example36.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | import java.util.List; 8 | import java.util.concurrent.ExecutionException; 9 | 10 | import org.elasticsearch.action.search.SearchResponse; 11 | import org.elasticsearch.client.transport.TransportClient; 12 | import org.elasticsearch.common.geo.ShapeRelation; 13 | import org.elasticsearch.common.geo.builders.CoordinatesBuilder; 14 | import org.elasticsearch.common.geo.builders.MultiPointBuilder; 15 | import org.elasticsearch.common.settings.Settings; 16 | import org.elasticsearch.common.transport.TransportAddress; 17 | import org.elasticsearch.index.query.GeoShapeQueryBuilder; 18 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 19 | import org.locationtech.jts.geom.Coordinate; 20 | 21 | 22 | /** 23 | * GEO QUERY API 24 | * */ 25 | public class Example36 { 26 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 27 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 28 | 29 | TransportClient client = 30 | new PreBuiltTransportClient(settings) 31 | .addTransportAddress(new TransportAddress( 32 | InetAddress.getByName("127.0.0.1"), 9300)); 33 | 34 | String INDEX_NAME = "movie_search_datatype"; 35 | String FIELD_NAME = "filmLocation"; 36 | 37 | List coodinates = new CoordinatesBuilder() 38 | .coordinate(0, 0) 39 | .coordinate(0, 10) 40 | .coordinate(10, 10) 41 | .coordinate(10, 0) 42 | .coordinate(0, 0) 43 | .build(); 44 | 45 | GeoShapeQueryBuilder queryBuilder = geoShapeQuery( 46 | FIELD_NAME, 47 | new MultiPointBuilder(coodinates) 48 | ); 49 | 50 | queryBuilder.relation(ShapeRelation.WITHIN); 51 | 52 | 53 | 54 | SearchResponse response = client.prepareSearch(INDEX_NAME) 55 | .setQuery(queryBuilder) 56 | .setSize(30).get(); 57 | 58 | 59 | 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example37.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import static org.elasticsearch.index.query.QueryBuilders.geoBoundingBoxQuery; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | import java.util.concurrent.ExecutionException; 8 | 9 | import org.elasticsearch.action.search.SearchResponse; 10 | import org.elasticsearch.client.transport.TransportClient; 11 | import org.elasticsearch.common.settings.Settings; 12 | import org.elasticsearch.common.transport.TransportAddress; 13 | import org.elasticsearch.index.query.QueryBuilder; 14 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 15 | 16 | /** 17 | * GEO QUERY API 18 | * */ 19 | public class Example37 { 20 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 21 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 22 | 23 | TransportClient client = 24 | new PreBuiltTransportClient(settings) 25 | .addTransportAddress(new TransportAddress( 26 | InetAddress.getByName("127.0.0.1"), 9300)); 27 | 28 | String INDEX_NAME = "movie_search_datatype"; 29 | String FIELD_NAME = "filmLocation"; 30 | 31 | QueryBuilder queryBuilder = geoBoundingBoxQuery(FIELD_NAME) 32 | .setCorners(40.73, -74.1, 33 | 40.717, -73.99); 34 | 35 | SearchResponse response = client.prepareSearch(INDEX_NAME) 36 | .setQuery(queryBuilder) 37 | .setSize(30).get(); 38 | 39 | 40 | 41 | 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example38.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import static org.elasticsearch.index.query.QueryBuilders.geoDistanceQuery; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | import java.util.concurrent.ExecutionException; 8 | 9 | import org.elasticsearch.action.search.SearchResponse; 10 | import org.elasticsearch.client.transport.TransportClient; 11 | import org.elasticsearch.common.settings.Settings; 12 | import org.elasticsearch.common.transport.TransportAddress; 13 | import org.elasticsearch.common.unit.DistanceUnit; 14 | import org.elasticsearch.index.query.QueryBuilder; 15 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 16 | 17 | /** 18 | * GEO QUERY API 19 | * */ 20 | public class Example38 { 21 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 22 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 23 | 24 | TransportClient client = 25 | new PreBuiltTransportClient(settings) 26 | .addTransportAddress(new TransportAddress( 27 | InetAddress.getByName("127.0.0.1"), 9300)); 28 | 29 | String INDEX_NAME = "movie_search_datatype"; 30 | String FIELD_NAME = "filmLocation"; 31 | 32 | QueryBuilder queryBuilder = geoDistanceQuery(FIELD_NAME) 33 | .point(40, -70) 34 | .distance(3, DistanceUnit.KILOMETERS); 35 | 36 | SearchResponse response = client.prepareSearch(INDEX_NAME) 37 | .setQuery(queryBuilder) 38 | .setSize(30).get(); 39 | 40 | 41 | 42 | 43 | 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/javacafe/client/transport/Example39.java: -------------------------------------------------------------------------------- 1 | package io.javacafe.client.transport; 2 | 3 | import static org.elasticsearch.index.query.QueryBuilders.geoPolygonQuery; 4 | 5 | import java.io.IOException; 6 | import java.net.InetAddress; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.concurrent.ExecutionException; 10 | 11 | import org.elasticsearch.action.search.SearchResponse; 12 | import org.elasticsearch.client.transport.TransportClient; 13 | import org.elasticsearch.common.geo.GeoPoint; 14 | import org.elasticsearch.common.settings.Settings; 15 | import org.elasticsearch.common.transport.TransportAddress; 16 | import org.elasticsearch.index.query.QueryBuilder; 17 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 18 | 19 | /** 20 | * GEO QUERY API 21 | * */ 22 | public class Example39 { 23 | public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { 24 | Settings settings = Settings.builder() .put("cluster.name", "javacafe-es").build(); 25 | 26 | TransportClient client = 27 | new PreBuiltTransportClient(settings) 28 | .addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("127.0.0.1"), 9300)); 30 | 31 | String INDEX_NAME = "movie_search_datatype"; 32 | String FIELD_NAME = "filmLocation"; 33 | 34 | List points = new ArrayList(); 35 | points.add(new GeoPoint(40, -70)); 36 | points.add(new GeoPoint(30, -80)); 37 | points.add(new GeoPoint(20, -90)); 38 | 39 | QueryBuilder queryBuilder = geoPolygonQuery(FIELD_NAME, points); 40 | 41 | SearchResponse response = client.prepareSearch(INDEX_NAME) 42 | .setQuery(queryBuilder) 43 | .setSize(30).get(); 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | } 52 | } 53 | --------------------------------------------------------------------------------