├── .gitignore ├── LICENSE ├── README.md ├── appendices └── Appendix D: ├── code ├── java │ └── Encoding.java └── python │ └── encode.py ├── datasets ├── books-kibana-dataset.txt ├── books.txt ├── bulk_mobile_phones_data.json ├── coffee_sales.txt ├── covid-26march2021.txt ├── london_restaurants.txt ├── mobile_phones_data_bulk.json ├── movie_bulk_data.json ├── movies2.json ├── products.txt ├── products2.txt ├── products_mapping.txt ├── restaurants.txt ├── three-books-kibana.txt ├── top-movies-kibana.txt ├── tv_sales.txt └── vector-search-sample.json ├── docker ├── 7.15.1_es_kibana.yml ├── elasticsearch-docker-8-1-2.yml ├── elasticsearch-docker-8-6-2.yml ├── one_node_es.yml └── one_node_kibana.yml └── kibana_scripts ├── appendix_ingest_pipelines.txt ├── ch02_getting_started.txt ├── ch04_mapping.txt ├── ch05_working_with_documents.txt ├── ch06_indexing_operations.txt ├── ch07_text_analysis.txt ├── ch08_search_basics.txt ├── ch09_term_level_queries.txt ├── ch10_full_text_queries.txt ├── ch11_compound_queries.txt ├── ch12_advanced_queries.txt ├── ch13_aggregations.txt ├── ch13_aggregations_index.txt ├── ch14_administration.txt └── ch_15_performance_and_trouble_shooting.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Give me a star if you love this repo! 2 | 3 | image 4 | 5 | 6 | # elasticsearch-in-action 7 | [Elasticsearch in Action (second edition) Book](https://www.manning.com/books/elasticsearch-in-action-second-edition?utm_source=mkonda&utm_medium=affiliate&utm_campaign=book_konda_elasticsearch_7_23_21&a_aid=mkonda&a_bid=edbc50d4) 8 | 9 | The [book's accompanying wiki pages](https://github.com/madhusudhankonda/elasticsearch-in-action/wiki) explains the code examples 10 | 11 | Here's the TOC 12 | 13 | 1. Overview 14 | 2. [Getting Started](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/babeea237dcc77f1d74f734e750347420e64ddc3/kibana_scripts/ch02_getting_started.txt) 15 | 3. [Architecture](https://github.com/madhusudhankonda/elasticsearch-in-action/wiki/Ch-3:-Architecture) 16 | 4. [Mapping](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch04_mapping.txt) 17 | 5. [Working with Documents](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch05_working_with_documents.txt) 18 | 6. [Indexing Operations](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch06_indexing_operations.txt) 19 | 7. [Text Analysis](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch07_text_analysis.txt) 20 | 8. [Search Basics](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch08_search_basics.txt) 21 | 9. [Term Level Queries](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch09_term_level_queries.txt) 22 | 10. [Full Text Queries](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch10_full_text_queries.txt) 23 | 11. [Compound Queries](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch11_compound_queries.txt) 24 | 12. [Advanced Queries](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch12_advanced_queries.txt) 25 | 13. [Aggregations](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch13_aggregations.txt) 26 | 14. [Administration](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch14_administration.txt) 27 | 15. [Performance and Troubleshooting](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/ch_15_performance_and_trouble_shooting.txt) 28 | 16. [Appendix A: Installing and configuring Elasticsearch and Kibana](https://github.com/madhusudhankonda/elasticsearch-in-action/wiki/Appendix-A:-Installation) 29 | 17. [Appendix B: Ingest Pipelines](https://github.com/madhusudhankonda/elasticsearch-in-action/blob/561c45d7991e8a1766a98ba1a58b0f0d836fc1fd/kibana_scripts/appendix_ingest_pipelines.txt) 30 | 31 | ## Disabling XPack Security for 8.x 32 | By default, 8.x version of Elasticsearch comes with security enabled. For simplicity and not getting the security in our way, we can disable the feature 33 | 34 | > :warning: **PLEASE DO NOT disable security in PRODUCTION** 35 | 36 | Edit config/elasticsearch.yml to add the following property at the end of the file: 37 | ```xpack.security.enabled: false``` 38 | -------------------------------------------------------------------------------- /appendices/Appendix D:: -------------------------------------------------------------------------------- 1 | Appenndix D goes here 2 | -------------------------------------------------------------------------------- /code/java/Encoding.java: -------------------------------------------------------------------------------- 1 | package com.chocolateminds.encoding; 2 | 3 | import java.util.Base64; 4 | 5 | /** 6 | * An utility class to encode a text as base64 7 | */ 8 | public class Encoding { 9 | String secretMessage = "Sunday Lunch at Konda's"; 10 | Base64.Encoder encoder = Base64.getEncoder(); 11 | Base64.Decoder decoder = Base64.getDecoder(); 12 | 13 | /** 14 | * Encoding a piece of string 15 | * @return 16 | */ 17 | private String encode(){ 18 | String encoded = Base64.getEncoder().encodeToString(secretMessage.getBytes()); 19 | return encoded; 20 | } 21 | 22 | public static void main(String[] args) { 23 | Encoding encoding = new Encoding(); 24 | System.out.println(encoding.encode()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /code/python/encode.py: -------------------------------------------------------------------------------- 1 | # A Pyton utility program to encode and decode strings to Base64 2 | import base64 3 | 4 | # Encoding the message as bytes 5 | secret_message_bytes = "Sunday Lunch at Konda's".encode('utf-8') 6 | 7 | # Encode the message to base64 8 | secret_message_base64 = base64.b64encode(secret_message_bytes) 9 | 10 | # Fetch the encoded message 11 | secret_message_base64_decode = secret_message_base64.decode('utf-8') 12 | 13 | # Print the message to the console 14 | print(secret_message_base64_decode) 15 | 16 | # It'll print: U3VuZGF5IEx1bmNoIGF0IEtvbmRhJ3M= 17 | -------------------------------------------------------------------------------- /datasets/books-kibana-dataset.txt: -------------------------------------------------------------------------------- 1 | POST _bulk 2 | {"index":{"_index":"books","_id":"1"}} 3 | {"title": "Core Java Volume I – Fundamentals","author": "Cay S. Horstmann","edition": 11, "synopsis": "Java reference book that offers a detailed explanation of various features of Core Java, including exception handling, interfaces, and lambda expressions. Significant highlights of the book include simple language, conciseness, and detailed examples.","amazon_rating": 4.6,"release_date": "2018-08-27","tags": ["Programming Languages, Java Programming"]} 4 | {"index":{"_index":"books","_id":"2"}} 5 | {"title": "Effective Java","author": "Joshua Bloch", "edition": 3,"synopsis": "A must-have book for every Java programmer and Java aspirant, Effective Java makes up for an excellent complementary read with other Java books or learning material. The book offers 78 best practices to follow for making the code better.", "amazon_rating": 4.7, "release_date": "2017-12-27", "tags": ["Object Oriented Software Design"]} 6 | {"index":{"_index":"books","_id":"3"}} 7 | {"title": "Java: A Beginner’s Guide", "author": "Herbert Schildt","edition": 8,"synopsis": "One of the most comprehensive books for learning Java. The book offers several hands-on exercises as well as a quiz section at the end of every chapter to let the readers self-evaluate their learning.","amazon_rating": 4.2,"release_date": "2018-11-20","tags": ["Software Design & Engineering", "Internet & Web"]} 8 | {"index":{"_index":"books","_id":"4"}} 9 | {"title": "Java - The Complete Reference","author": "Herbert Schildt","edition": 11,"synopsis": "Convenient Java reference book examining essential portions of the Java API library, Java. The book is full of discussions and apt examples to better Java learning.","amazon_rating": 4.4,"release_date": "2019-03-19","tags": ["Software Design & Engineering", "Internet & Web", "Computer Programming Language & Tool"]} 10 | {"index":{"_index":"books","_id":"5"}} 11 | {"title": "Head First Java","author": "Kathy Sierra and Bert Bates","edition":2, "synopsis": "The most important selling points of Head First Java is its simplicity and super-effective real-life analogies that pertain to the Java programming concepts.","amazon_rating": 4.3,"release_date": "2005-02-18","tags": ["IT Certification Exams", "Object-Oriented Software Design","Design Pattern Programming"]} 12 | {"index":{"_index":"books","_id":"6"}} 13 | {"title": "Java Concurrency in Practice","author": "Brian Goetz with Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, and Doug Lea","edition": 1,"synopsis": "Java Concurrency in Practice is one of the best Java programming books to develop a rich understanding of concurrency and multithreading.","amazon_rating": 4.3,"release_date": "2006-05-09","tags": ["Computer Science Books", "Programming Languages", "Java Programming"]} 14 | {"index":{"_index":"books","_id":"7"}} 15 | {"title": "Test-Driven: TDD and Acceptance TDD for Java Developers","author": "Lasse Koskela","edition": 1,"synopsis": "Test-Driven is an excellent book for learning how to write unique automation testing programs. It is a must-have book for those Java developers that prioritize code quality as well as have a knack for writing unit, integration, and automation tests.","amazon_rating": 4.1,"release_date": "2007-10-22","tags": ["Software Architecture", "Software Design & Engineering", "Java Programming"]} 16 | {"index":{"_index":"books","_id":"8"}} 17 | {"title": "Head First Object-Oriented Analysis Design","author": "Brett D. McLaughlin, Gary Pollice & David West","edition": 1,"synopsis": "Head First is one of the most beautiful finest book series ever written on Java programming language. Another gem in the series is the Head First Object-Oriented Analysis Design.","amazon_rating": 3.9,"release_date": "2014-04-29","tags": ["Introductory & Beginning Programming", "Object-Oriented Software Design", "Java Programming"]} 18 | {"index":{"_index":"books","_id":"9"}} 19 | {"title": "Java Performance: The Definite Guide","author": "Scott Oaks","edition": 1,"synopsis": "Garbage collection, JVM, and performance tuning are some of the most favorable aspects of the Java programming language. It educates readers about maximizing Java threading and synchronization performance features, improve Java-driven database application performance, tackle performance issues","amazon_rating": 4.1,"release_date": "2014-03-04","tags": ["Design Pattern Programming", "Object-Oriented Software Design", "Computer Programming Language & Tool"]} 20 | {"index":{"_index":"books","_id":"10"}} 21 | {"title": "Head First Design Patterns", "author": "Eric Freeman & Elisabeth Robson with Kathy Sierra & Bert Bates","edition": 10,"synopsis": "Head First Design Patterns is one of the leading books to build that particular understanding of the Java programming language." ,"amazon_rating": 4.5,"release_date": "2014-03-04","tags": ["Design Pattern Programming", "Object-Oriented Software Design eTextbooks", "Web Development & Design eTextbooks"]} 22 | -------------------------------------------------------------------------------- /datasets/coffee_sales.txt: -------------------------------------------------------------------------------- 1 | PUT coffee_sales/_bulk 2 | {"index":{"_id":"1"}} 3 | {"date":"2022-09-01","sales":{"cappuccino":23,"latte":12,"americano":9,"tea":7},"price":{"cappuccino":2.50,"latte":2.40,"americano":2.10,"tea":1.50}} 4 | {"index":{"_id":"2"}} 5 | { "date":"2022-09-02","sales":{"cappuccino":40,"latte":16,"americano":19,"tea":15},"price":{"cappuccino":2.50,"latte":2.40,"americano":2.10,"tea":1.50}} 6 | 7 | -------------------------------------------------------------------------------- /datasets/covid-26march2021.txt: -------------------------------------------------------------------------------- 1 | POST covid/_bulk 2 | {"index":{}} 3 | {"country":"United States of America","date":"2021-03-26","cases":30853032,"deaths":561142,"recovered":23275268,"critical":8610} 4 | {"index":{}} 5 | {"country":"Brazil","date":"2021-03-26","cases":12407323,"deaths":307326,"recovered":10824095,"critical":8318} 6 | {"index":{}} 7 | {"country":"India","date":"2021-03-26","cases":11908373,"deaths":161275,"recovered":11292849,"critical":8944} 8 | {"index":{}} 9 | {"country":"Russia","date":"2021-03-26","cases":4501859,"deaths":97017,"recovered":4120161,"critical":2300} 10 | {"index":{}} 11 | {"country":"France","date":"2021-03-26","cases":4465956,"deaths":94275,"recovered":288062,"critical":4766} 12 | {"index":{}} 13 | {"country":"United kingdom","date":"2021-03-26","cases":4325315,"deaths":126515,"recovered":3768434,"critical":630} 14 | {"index":{}} 15 | {"country":"Italy","date":"2021-03-26","cases":3488619,"deaths":107256,"recovered":2814652,"critical":3628} 16 | {"index":{}} 17 | {"country":"Spain","date":"2021-03-26","cases":3255324,"deaths":75010,"recovered":3016247,"critical":1830} 18 | {"index":{}} 19 | {"country":"Turkey","date":"2021-03-26","cases":3149094,"deaths":30772,"recovered":2921037,"critical":1810} 20 | {"index":{}} 21 | {"country":"Germany","date":"2021-03-26","cases":2754002,"deaths":76303,"recovered":2467600,"critical":3209} 22 | -------------------------------------------------------------------------------- /datasets/london_restaurants.txt: -------------------------------------------------------------------------------- 1 | # Create a mapping for restaurants 2 | PUT restaurants 3 | { 4 | "mappings": { 5 | "properties": { 6 | "name":{ 7 | "type": "text" 8 | }, 9 | "town_centre":{ 10 | "type": "geo_point" 11 | }, 12 | "location":{ 13 | "type": "geo_point" 14 | }, 15 | "category":{ 16 | "type":"text" 17 | }, 18 | "hygenie_rating":{ 19 | "type": "short" 20 | }, 21 | "borough":{ 22 | "type":"text" 23 | } 24 | } 25 | } 26 | } 27 | 28 | # A big thanks to Shirang Dixit for his Kaggle's dataset: 29 | # https://www.kaggle.com/datasets/shrirangdixit/restaurants-and-venues-in-london?resource=download&select=top_100.csv 30 | 31 | # Index the restuarants data 32 | 33 | PUT _bulk 34 | {"index":{"_index":"restaurants","_id":"1"}} 35 | {"borough": "Barking and Dagenham", "name": "Costa Coffee", "town_center": "51.574780001107, 0.174409970722365", "location": "51.5768901505657, 0.179497329179776", "category": "Coffee Shop"} 36 | {"index":{"_index":"restaurants","_id":"2"}} 37 | {"borough": "Barking and Dagenham", "name": "Ciao Bella", "town_center": "51.574780001107, 0.174409970722365", "location": "51.5761031644746, 0.182819451657697", "category": "Italian Restaurant"} 38 | {"index":{"_index":"restaurants","_id":"3"}} 39 | {"borough": "Barking and Dagenham", "name": "Costa Coffee", "town_center": "51.574780001107, 0.174409970722365", "location": "51.5764810641186, 0.182447859463851", "category": "Coffee Shop"} 40 | {"index":{"_index":"restaurants","_id":"4"}} 41 | {"borough": "Barking and Dagenham", "name": "Braza", "town_center": "51.574780001107, 0.174409970722365", "location": "51.5763438553126, 0.181760001988972", "category": "Brazilian Restaurant"} 42 | {"index":{"_index":"restaurants","_id":"5"}} 43 | {"borough": "Barking and Dagenham", "name": "The Bull", "town_center": "51.574780001107, 0.174409970722365", "location": "51.5795205127607, 0.182871095573334", "category": "Pub"} 44 | {"index":{"_index":"restaurants","_id":"6"}} 45 | {"borough": "Barking and Dagenham", "name": "Patisserie Valerie", "town_center": "51.574780001107, 0.174409970722365", "location": "51.5764467677515, 0.179965973726707", "category": "Cafe"} 46 | {"index":{"_index":"restaurants","_id":"7"}} 47 | {"borough": "Barking and Dagenham", "name": "Starbucks", "town_center": "51.574780001107, 0.174409970722365", "location": "51.576281, 0.181187", "category": "Coffee Shop"} 48 | {"index":{"_index":"restaurants","_id":"8"}} 49 | {"borough": "Barking and Dagenham", "name": "Teapot Cafe", "town_center": "51.574780001107, 0.174409970722365", "location": "51.579782, 0.182306", "category": "Cafe"} 50 | {"index":{"_index":"restaurants","_id":"9"}} 51 | {"borough": "Barking and Dagenham", "name": "Harris + Hoole", "town_center": "51.574780001107, 0.174409970722365", "location": "51.5656137812814, 0.191278187889649", "category": "Coffee Shop"} 52 | {"index":{"_index":"restaurants","_id":"10"}} 53 | {"borough": "Barking and Dagenham", "name": "Frankie & Benny's", "town_center": "51.574780001107, 0.174409970722365", "location": "51.5751804, 0.1801494", "category": "American Restaurant"} 54 | {"index":{"_index":"restaurants","_id":"11"}} 55 | {"borough": "Barnet", "name": "The King's Arms", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.525753907299, -0.0658676349732126", "category": "Pub"} 56 | {"index":{"_index":"restaurants","_id":"12"}} 57 | {"borough": "Barnet", "name": "Sam's Cafe", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.5264242861641, -0.0650555900273512", "category": "Cafe"} 58 | {"index":{"_index":"restaurants","_id":"13"}} 59 | {"borough": "Barnet", "name": "Brawn", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.5289129240344, -0.0703129817333181", "category": "Restaurant"} 60 | {"index":{"_index":"restaurants","_id":"14"}} 61 | {"borough": "Barnet", "name": "Tas Firin", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.5254584974656, -0.0702727253628311", "category": "Turkish Restaurant"} 62 | {"index":{"_index":"restaurants","_id":"15"}} 63 | {"borough": "Barnet", "name": "E Pellicci", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.526516, -0.063426", "category": "Cafe"} 64 | {"index":{"_index":"restaurants","_id":"16"}} 65 | {"borough": "Barnet", "name": "Holy Shot", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.5254297867875, -0.0704955175906381", "category": "Coffee Shop"} 66 | {"index":{"_index":"restaurants","_id":"17"}} 67 | {"borough": "Barnet", "name": "Well & Bucket", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.5252935552737, -0.0709888374442932", "category": "Pub"} 68 | {"index":{"_index":"restaurants","_id":"18"}} 69 | {"borough": "Barnet", "name": "Jonestown", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.5260919169767, -0.0679361253278925", "category": "Coffee Shop"} 70 | {"index":{"_index":"restaurants","_id":"19"}} 71 | {"borough": "Barnet", "name": "Beigel Bake", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.5245132556491, -0.0716434492960825", "category": "Bagel Shop"} 72 | {"index":{"_index":"restaurants","_id":"20"}} 73 | {"borough": "Barnet", "name": "The Carpenters Arms", "town_center": "51.527094989936, -0.0668257039632054", "location": "51.523927250026, -0.0674413496578882", "category": "Pub"} 74 | {"index":{"_index":"restaurants","_id":"21"}} 75 | {"borough": "Bexley", "name": "The Lale Restaurant", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.4509414781371, 0.0514545861448455", "category": "Fast Food Restaurant"} 76 | {"index":{"_index":"restaurants","_id":"22"}} 77 | {"borough": "Bexley", "name": "Nando's", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.45054026, 0.05653644", "category": "Portuguese Restaurant"} 78 | {"index":{"_index":"restaurants","_id":"23"}} 79 | {"borough": "Bexley", "name": "Rixos", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.450678, 0.057724", "category": "Mediterranean Restaurant"} 80 | {"index":{"_index":"restaurants","_id":"24"}} 81 | {"borough": "Bexley", "name": "Costa Coffee", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.451008251248, 0.0541388278388066", "category": "Coffee Shop"} 82 | {"index":{"_index":"restaurants","_id":"25"}} 83 | {"borough": "Bexley", "name": "Eltham GPO", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.4503454752311, 0.0540715508832256", "category": "Pub"} 84 | {"index":{"_index":"restaurants","_id":"26"}} 85 | {"borough": "Bexley", "name": "The Park Tavern", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.4498344269546, 0.0543999993955841", "category": "Bar"} 86 | {"index":{"_index":"restaurants","_id":"27"}} 87 | {"borough": "Bexley", "name": "Oxleas Wood Cafe", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.4665009464818, 0.0697064082304458", "category": "Cafe"} 88 | {"index":{"_index":"restaurants","_id":"28"}} 89 | {"borough": "Bexley", "name": "Rising Sun", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.4507943380767, 0.0585335705495846", "category": "Pub"} 90 | {"index":{"_index":"restaurants","_id":"29"}} 91 | {"borough": "Bexley", "name": "Greggs", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.4509658813476, 0.0562703981995582", "category": "Bakery"} 92 | {"index":{"_index":"restaurants","_id":"30"}} 93 | {"borough": "Bexley", "name": "Ziyafet", "town_center": "51.4520777153566, 0.0699310359401914", "location": "51.4507589986404, 0.0579818639303895", "category": "Mediterranean Restaurant"} 94 | {"index":{"_index":"restaurants","_id":"31"}} 95 | {"borough": "Brent", "name": "Vero Caffe", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6151121664419, -0.190732068656857", "category": "Cafe"} 96 | {"index":{"_index":"restaurants","_id":"32"}} 97 | {"borough": "Brent", "name": "Michaels", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6151839858547, -0.190852863254336", "category": "Cafe"} 98 | {"index":{"_index":"restaurants","_id":"33"}} 99 | {"borough": "Brent", "name": "Divans", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6054713446698, -0.18784697192525", "category": "Turkish Restaurant"} 100 | {"index":{"_index":"restaurants","_id":"34"}} 101 | {"borough": "Brent", "name": "Tintico", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.601117071909, -0.193745059397798", "category": "Coffee Shop"} 102 | {"index":{"_index":"restaurants","_id":"35"}} 103 | {"borough": "Brent", "name": "Ishtah Restaurant", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6000001468419, -0.19599437713623", "category": "Turkish Restaurant"} 104 | {"index":{"_index":"restaurants","_id":"36"}} 105 | {"borough": "Brent", "name": "Beheshte Barin", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6044408380993, -0.18901225817288", "category": "Persian Restaurant"} 106 | {"index":{"_index":"restaurants","_id":"37"}} 107 | {"borough": "Brent", "name": "Bohemia Bar", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6153029887064, -0.176606810713685", "category": "Bar"} 108 | {"index":{"_index":"restaurants","_id":"38"}} 109 | {"borough": "Brent", "name": "Boulangerie Joie De Vie", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6140791870559, -0.176805054900558", "category": "Breakfast Spot"} 110 | {"index":{"_index":"restaurants","_id":"39"}} 111 | {"borough": "Brent", "name": "JOE & THE JUICE", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6012515, -0.1937675", "category": "Juice Bar"} 112 | {"index":{"_index":"restaurants","_id":"40"}} 113 | {"borough": "Brent", "name": "Durum", "town_center": "51.6097831150824, -0.194672008019029", "location": "51.6046125660528, -0.188849152912733", "category": "Middle Eastern Restaurant"} 114 | {"index":{"_index":"restaurants","_id":"41"}} 115 | {"borough": "Bromley", "name": "K\u82d4y\u861dm", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.6039089201188, -0.0679442988499194", "category": "Mediterranean Restaurant"} 116 | {"index":{"_index":"restaurants","_id":"42"}} 117 | {"borough": "Bromley", "name": "San Marco", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.5942556990959, -0.0700769248332533", "category": "Italian Restaurant"} 118 | {"index":{"_index":"restaurants","_id":"43"}} 119 | {"borough": "Bromley", "name": "The Beehive", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.592203, -0.069205", "category": "Pub"} 120 | {"index":{"_index":"restaurants","_id":"44"}} 121 | {"borough": "Bromley", "name": "Pressure Drop Brewery & Taproom", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.5905977319284, -0.0579861082470803", "category": "Brewery"} 122 | {"index":{"_index":"restaurants","_id":"45"}} 123 | {"borough": "Bromley", "name": "Beavertown Brewery", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.5910143775121, -0.0567056428947125", "category": "Brewery"} 124 | {"index":{"_index":"restaurants","_id":"46"}} 125 | {"borough": "Bromley", "name": "The Bricklayers Arms", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.6058591330067, -0.0681968627826005", "category": "Pub"} 126 | {"index":{"_index":"restaurants","_id":"47"}} 127 | {"borough": "Bromley", "name": "The Antwerp Arms", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.6017749589411, -0.0747621657183833", "category": "Pub"} 128 | {"index":{"_index":"restaurants","_id":"48"}} 129 | {"borough": "Bromley", "name": "Styx Bar", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.5894618157794, -0.0611187776416513", "category": "Bar"} 130 | {"index":{"_index":"restaurants","_id":"49"}} 131 | {"borough": "Bromley", "name": "Bill Nicholson Pub", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.6057869950186, -0.0617015153439127", "category": "Pub"} 132 | {"index":{"_index":"restaurants","_id":"50"}} 133 | {"borough": "Bromley", "name": "The High Cross", "town_center": "51.6015105745503, -0.0663650798170126", "location": "51.589317, -0.070183", "category": "Pub"} 134 | {"index":{"_index":"restaurants","_id":"51"}} 135 | {"borough": "Camden", "name": "Granger & Co.", "town_center": "51.53236, -0.127959999999973", "location": "51.53260599028, -0.125274774925295", "category": "Breakfast Spot"} 136 | {"index":{"_index":"restaurants","_id":"52"}} 137 | {"borough": "Camden", "name": "The Coal Office", "town_center": "51.53236, -0.127959999999973", "location": "51.5350334053233, -0.126354341029567", "category": "Middle Eastern Restaurant"} 138 | {"index":{"_index":"restaurants","_id":"53"}} 139 | {"borough": "Camden", "name": "German Gymnasium", "town_center": "51.53236, -0.127959999999973", "location": "51.5323924057199, -0.125266572012957", "category": "Modern European Restaurant"} 140 | {"index":{"_index":"restaurants","_id":"54"}} 141 | {"borough": "Camden", "name": "Dishoom", "town_center": "51.53236, -0.127959999999973", "location": "51.5360803511111, -0.125733423886154", "category": "Indian Restaurant"} 142 | {"index":{"_index":"restaurants","_id":"55"}} 143 | {"borough": "Camden", "name": "Caravan King's Cross", "town_center": "51.53236, -0.127959999999973", "location": "51.5353309005303, -0.125238941536818", "category": "Breakfast Spot"} 144 | {"index":{"_index":"restaurants","_id":"56"}} 145 | {"borough": "Camden", "name": "Redemption Roasters", "town_center": "51.53236, -0.127959999999973", "location": "51.53578653699, -0.125830995565926", "category": "Coffee Shop"} 146 | {"index":{"_index":"restaurants","_id":"57"}} 147 | {"borough": "Camden", "name": "Spiritland King's Cross", "town_center": "51.53236, -0.127959999999973", "location": "51.5365880173102, -0.125647249431435", "category": "Bar"} 148 | {"index":{"_index":"restaurants","_id":"58"}} 149 | {"borough": "Camden", "name": "Barrafina", "town_center": "51.53236, -0.127959999999973", "location": "51.5359001107097, -0.127014241297244", "category": "Tapas Restaurant"} 150 | {"index":{"_index":"restaurants","_id":"59"}} 151 | {"borough": "Camden", "name": "Pizza Union", "town_center": "51.53236, -0.127959999999973", "location": "51.5309843732385, -0.119933337078844", "category": "Pizza Place"} 152 | {"index":{"_index":"restaurants","_id":"60"}} 153 | {"borough": "Camden", "name": "Aux Pains de Papy", "town_center": "51.53236, -0.127959999999973", "location": "51.52934, -0.12030311", "category": "Bakery"} 154 | {"index":{"_index":"restaurants","_id":"61"}} 155 | {"borough": "Croydon", "name": "Forks & Green", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.5864033288793, -0.0876568737106018", "category": "Coffee Shop"} 156 | {"index":{"_index":"restaurants","_id":"62"}} 157 | {"borough": "Croydon", "name": "San Marco", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.5942556990959, -0.0700769248332533", "category": "Italian Restaurant"} 158 | {"index":{"_index":"restaurants","_id":"63"}} 159 | {"borough": "Croydon", "name": "The Beehive", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.592203, -0.069205", "category": "Pub"} 160 | {"index":{"_index":"restaurants","_id":"64"}} 161 | {"borough": "Croydon", "name": "True Craft", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.5844548988647, -0.0759145443098913", "category": "Pub"} 162 | {"index":{"_index":"restaurants","_id":"65"}} 163 | {"borough": "Croydon", "name": "Big Bowl Noodle", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.5890428491221, -0.0798050088275486", "category": "Chinese Restaurant"} 164 | {"index":{"_index":"restaurants","_id":"66"}} 165 | {"borough": "Croydon", "name": "Blighty Tottenham", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.5857315913233, -0.071639098067246", "category": "Coffee Shop"} 166 | {"index":{"_index":"restaurants","_id":"67"}} 167 | {"borough": "Croydon", "name": "The High Cross", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.589317, -0.070183", "category": "Pub"} 168 | "index":{"_index":"restaurants","_id":"68"}} 169 | {"borough": "Croydon", "name": "Neighbours Fish Bar", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.5936938448642, -0.078361531163436", "category": "Fast Food Restaurant"} 170 | {"index":{"_index":"restaurants","_id":"69"}} 171 | {"borough": "Croydon", "name": "The Westbury", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.5934584725395, -0.0984119411285734", "category": "Pub"} 172 | {"index":{"_index":"restaurants","_id":"70"}} 173 | {"borough": "Croydon", "name": "Durak Tantuni", "town_center": "51.5934799851819, -0.0834199693442485", "location": "51.5863071648797, -0.0948641974566496", "category": "Turkish Restaurant"} 174 | {"index":{"_index":"restaurants","_id":"71"}} 175 | {"borough": "Ealing", "name": "WA Cafe", "town_center": "51.51406, -0.30072999999993", "location": "51.5159443047932, -0.302204197643989", "category": "Dessert Shop"} 176 | {"index":{"_index":"restaurants","_id":"72"}} 177 | {"borough": "Ealing", "name": "Electric Coffee Co.", "town_center": "51.51406, -0.30072999999993", "location": "51.5153911156112, -0.30229740345209", "category": "Coffee Shop"} 178 | {"index":{"_index":"restaurants","_id":"73"}} 179 | {"borough": "Ealing", "name": "Hare and Tortoise", "town_center": "51.51406, -0.30072999999993", "location": "51.515635, -0.302106", "category": "Noodle House"} 180 | {"index":{"_index":"restaurants","_id":"74"}} 181 | {"borough": "Ealing", "name": "The Drapers Arms", "town_center": "51.51406, -0.30072999999993", "location": "51.5116061052896, -0.305163115370252", "category": "Pub"} 182 | {"index":{"_index":"restaurants","_id":"75"}} 183 | {"borough": "Ealing", "name": "Pho", "town_center": "51.51406, -0.30072999999993", "location": "51.513200351339, -0.306250120386768", "category": "Vietnamese Restaurant"} 184 | {"index":{"_index":"restaurants","_id":"76"}} 185 | {"borough": "Ealing", "name": "Franco Manca", "town_center": "51.51406, -0.30072999999993", "location": "51.5129934137107, -0.306861265576397", "category": "Pizza Place"} 186 | {"index":{"_index":"restaurants","_id":"77"}} 187 | {"borough": "Ealing", "name": "Artisan Coffee", "town_center": "51.51406, -0.30072999999993", "location": "51.5130239121096, -0.306655060235716", "category": "Coffee Shop"} 188 | {"index":{"_index":"restaurants","_id":"78"}} 189 | {"borough": "Ealing", "name": "Bee Hive", "town_center": "51.51406, -0.30072999999993", "location": "51.5104353629262, -0.3054168881695", "category": "Cafe"} 190 | {"index":{"_index":"restaurants","_id":"79"}} 191 | {"borough": "Ealing", "name": "Turtle Bay", "town_center": "51.51406, -0.30072999999993", "location": "51.512064951366, -0.304737682171537", "category": "Caribbean Restaurant"} 192 | {"index":{"_index":"restaurants","_id":"80"}} 193 | {"borough": "Ealing", "name": "The Kings Arms", "town_center": "51.51406, -0.30072999999993", "location": "51.5109807572851, -0.302002674073637", "category": "Pub"} 194 | {"index":{"_index":"restaurants","_id":"81"}} 195 | {"borough": "Enfield", "name": "Toconoco", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.5383104191455, -0.0780980601377977", "category": "Udon Restaurant"} 196 | {"index":{"_index":"restaurants","_id":"82"}} 197 | {"borough": "Enfield", "name": "Chick 'n' Sours", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.5412919201058, -0.0763088119457662", "category": "Fried Chicken Joint"} 198 | {"index":{"_index":"restaurants","_id":"83"}} 199 | {"borough": "Enfield", "name": "Berber & Q", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.536882, -0.07581", "category": "Middle Eastern Restaurant"} 200 | {"index":{"_index":"restaurants","_id":"84"}} 201 | {"borough": "Enfield", "name": "Towpath Cafe", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.537169, -0.08118", "category": "Coffee Shop"} 202 | {"index":{"_index":"restaurants","_id":"85"}} 203 | {"borough": "Enfield", "name": "Arepa & Co", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.5370471235717, -0.0801467669382093", "category": "Arepa Restaurant"} 204 | {"index":{"_index":"restaurants","_id":"86"}} 205 | {"borough": "Enfield", "name": "The Scolt Head", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.5431308529259, -0.0815900760000717", "category": "Pub"} 206 | {"index":{"_index":"restaurants","_id":"87"}} 207 | {"borough": "Enfield", "name": "Madame Pigg", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.543389, -0.075859", "category": "Restaurant"} 208 | {"index":{"_index":"restaurants","_id":"88"}} 209 | {"borough": "Enfield", "name": "Andu's cafe", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.5445198364757, -0.0759062189011869", "category": "Ethiopian Restaurant"} 210 | {"index":{"_index":"restaurants","_id":"89"}} 211 | {"borough": "Enfield", "name": "Better Health Bakery", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.5373758194978, -0.0751918750572799", "category": "Bakery"} 212 | {"index":{"_index":"restaurants","_id":"90"}} 213 | {"borough": "Enfield", "name": "Signature Brew Taproom & Venue", "town_center": "51.5400236215167, -0.0775021537472357", "location": "51.536617, -0.07570233", "category": "Beer Bar"} 214 | {"index":{"_index":"restaurants","_id":"91"}} 215 | {"borough": "Greenwich", "name": "Cutty Sark Tavern", "town_center": "51.48454, 0.00275000000004865", "location": "51.4864158641669, -0.000485650977134305", "category": "Pub"} 216 | {"index":{"_index":"restaurants","_id":"92"}} 217 | {"borough": "Greenwich", "name": "Midpoint", "town_center": "51.48454, 0.00275000000004865", "location": "51.486043, -0.000911", "category": "Turkish Restaurant"} 218 | {"index":{"_index":"restaurants","_id":"93"}} 219 | {"borough": "Greenwich", "name": "Sefa", "town_center": "51.48454, 0.00275000000004865", "location": "51.4845238644171, 0.00253671792443989", "category": "Turkish Restaurant"} 220 | {"index":{"_index":"restaurants","_id":"94"}} 221 | {"borough": "Greenwich", "name": "Zaibatsu", "town_center": "51.48454, 0.00275000000004865", "location": "51.4840949352715, 0.00137609013534067", "category": "Japanese Restaurant"} 222 | {"index":{"_index":"restaurants","_id":"95"}} 223 | {"borough": "Greenwich", "name": "The Plume of Feathers", "town_center": "51.48454, 0.00275000000004865", "location": "51.4819450403517, -0.00112598463407319", "category": "Pub"} 224 | {"index":{"_index":"restaurants","_id":"96"}} 225 | {"borough": "Greenwich", "name": "Mountain View Greenwich", "town_center": "51.48454, 0.00275000000004865", "location": "51.484824, 0.003913", "category": "Indian Restaurant"} 226 | {"index":{"_index":"restaurants","_id":"97"}} 227 | {"borough": "Greenwich", "name": "Effes Meze", "town_center": "51.48454, 0.00275000000004865", "location": "51.4850160366829, 0.00420840980734031", "category": "Mediterranean Restaurant"} 228 | {"index":{"_index":"restaurants","_id":"98"}} 229 | {"borough": "Greenwich", "name": "Theatre of Wine", "town_center": "51.48454, 0.00275000000004865", "location": "51.4838404206285, 0.000603263673400172", "category": "Wine Shop"} 230 | {"index":{"_index":"restaurants","_id":"99"}} 231 | {"borough": "Greenwich", "name": "River Ale House", "town_center": "51.48454, 0.00275000000004865", "location": "51.4861666603242, 0.0133654475212097", "category": "Pub"} 232 | {"index":{"_index":"restaurants","_id":"100"}} 233 | {"borough": "Greenwich", "name": "Meantime Brewing Company", "town_center": "51.48454, 0.00275000000004865", "location": "51.4895678225253, 0.00857507908913158", "category": "Brewery"} 234 | -------------------------------------------------------------------------------- /datasets/movie_bulk_data.json: -------------------------------------------------------------------------------- 1 | POST _bulk 2 | {"index":{"_index":"movies","_id":"1"}} 3 | {"title": "The Shawshank Redemption","synopsis": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.","actors": ["Tim Robbins", "Morgan Freeman", "Bob Gunton", "William Sadler"] ,"director":" Frank Darabont ","rating":"9.3","certificate":"R","genre": "Drama "} 4 | {"index":{"_index":"movies","_id":"2"}} 5 | {"title": "The Godfather","synopsis": "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.","actors": ["Marlon Brando", "Al Pacino", "James Caan", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":"9.2","certificate":"R","genre": ["Crime", "Drama"] } 6 | {"index":{"_index":"movies","_id":"3"}} 7 | {"title": "The Dark Knight","synopsis": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, Batman must accept one of the greatest psychological and physical tests of his ability to fight injustice.","actors": ["Christian Bale", "Heath Ledger", "Aaron Eckhart", "Michael Caine"] ,"director":" Christopher Nolan ","rating":"9.0","certificate":"PG-13","genre": ["Action", "Crime", "Drama"] } 8 | {"index":{"_index":"movies","_id":"4"}} 9 | {"title": "The Godfather: Part II","synopsis": "The early life and career of Vito Corleone in 1920s New York City is portrayed, while his son, Michael, expands and tightens his grip on the family crime syndicate.","actors": ["Al Pacino", "Robert De Niro", "Robert Duvall", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":"9.0","certificate":"R","genre": ["Crime", "Drama"] } 10 | {"index":{"_index":"movies","_id":"5"}} 11 | {"title": "12 Angry Men","synopsis": "A jury holdout attempts to prevent a miscarriage of justice by forcing his colleagues to reconsider the evidence.","actors": ["Henry Fonda", "Lee J. Cobb", "Martin Balsam", " John Fiedler"] ,"director":" Sidney Lumet ","rating":"9.0","certificate":"Approved","genre": ["Crime", "Drama"] } 12 | {"index":{"_index":"movies","_id":"6"}} 13 | {"title": "The Lord of the Rings: The Return of the King","synopsis": "Gandalf and Aragorn lead the World of Men against Saurons's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring.","actors": ["Elijah Wood", "Viggo Mortensen", "Ian McKellen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":"8.9","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] } 14 | {"index":{"_index":"movies","_id":"7"}} 15 | {"title": "Pulp Fiction","synopsis": "The lives of two mob hitmen, a boxer, a gangster and his wife, and a pair of diner bandits intertwine in four tales of violence and redemption.","actors": ["John Travolta", "Uma Thurman", "Samuel L. Jackson", "Bruce Willis"] ,"director":" Quentin Tarantino ","rating":"8.9","certificate":"R","genre": ["Crime", "Drama"] } 16 | {"index":{"_index":"movies","_id":"8"}} 17 | {"title": "Schindler's List","synopsis": "In German-occupied Poland during World War II, industrialist Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis.","actors": ["Liam Neeson", "Ralph Fiennes", "Ben Kingsley", "Caroline Goodall"] ,"director":" Steven Spielberg ","rating":"8.9","certificate":"R","genre": ["Biography", "Drama", "History"] } 18 | {"index":{"_index":"movies","_id":"9"}} 19 | {"title": "Inception","synopsis": "A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.","actors": ["Leonardo DiCaprio", "Joseph Gordon-Levitt", "Elliot Page", "Ken Watanabe"] ,"director":" Christopher Nolan ","rating":"8.8","certificate":"PG-13","genre": ["Action", "Adventure", "Sci-Fi"] } 20 | {"index":{"_index":"movies","_id":"10"}} 21 | {"title": "Fight Club","synopsis": "An insomniac office worker and a devil-may-care soap maker form an underground fight club that evolves into much more.","actors": ["Brad Pitt", "Edward Norton", "Meat Loaf", "Zach Grenier"] ,"director":" David Fincher ","rating":"8.8","certificate":"R","genre": "Drama"} 22 | {"index":{"_index":"movies","_id":"11"}} 23 | {"title": "The Lord of the Rings: The Fellowship of the Ring","synopsis": "A meek Hobbit from the Shire and eight companions set out on a journey to destroy the powerful One Ring and save Middle-earth from the Dark Lord Sauron.","actors": ["Elijah Wood", "Ian McKellen", "Orlando Bloom", "Sean Bean"] ,"director":" Peter Jackson ","rating":"8.8","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] } 24 | {"index":{"_index":"movies","_id":"12"}} 25 | {"title": "Forrest Gump","synopsis": "The presidencies of Kennedy and Johnson, the Vietnam War, the Watergate scandal and other historical events unfold from the perspective of an Alabama man with an IQ of 75, whose only desire is to be reunited with his childhood sweetheart.","actors": ["Tom Hanks", "Robin Wright", "Gary Sinise", "Sally Field"] ,"director":" Robert Zemeckis ","rating":"8.8","certificate":"PG-13","genre": ["Drama", "Romance"] } 26 | {"index":{"_index":"movies","_id":"13"}} 27 | {"title": "The Good, the Bad and the Ugly","synopsis": "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.","actors": ["Clint Eastwood", "Eli Wallach", "Lee Van Cleef", "Aldo Giuffrè"] ,"director":" Sergio Leone ","rating":"8.8","certificate":"R","genre": "Western"} 28 | {"index":{"_index":"movies","_id":"14"}} 29 | {"title": "The Lord of the Rings: The Two Towers","synopsis": "While Frodo and Sam edge closer to Mordor with the help of the shifty Gollum, the divided fellowship makes a stand against Sauron's new ally, Saruman, and his hordes of Isengard.","actors": ["Elijah Wood", "Ian McKellen", "Viggo Mortensen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":"8.7","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"]} 30 | {"index":{"_index":"movies","_id":"15"}} 31 | {"title": "The Matrix","synopsis": "When a beautiful stranger leads computer hacker Neo to a forbidding underworld, he discovers the shocking truth--the life he knows is the elaborate deception of an evil cyber-intelligence.","actors": ["Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss", "Hugo Weaving"] ,"director":["Lana Wachowski", "Lilly Wachowski"] ,"rating":"8.7","certificate":"R","genre": ["Action", "Sci-Fi"] } 32 | {"index":{"_index":"movies","_id":"16"}} 33 | {"title": "Goodfellas","synopsis": "The story of Henry Hill and his life in the mob, covering his relationship with his wife Karen Hill and his mob partners Jimmy Conway and Tommy DeVito in the Italian-American crime syndicate.","actors": ["Robert De Niro", "Ray Liotta", "Joe Pesci", "Lorraine Bracco"] ,"director":" Martin Scorsese ","rating":"8.7","certificate":"R","genre": ["Biography", "Drama", "Crime"] } 34 | {"index":{"_index":"movies","_id":"17"}} 35 | {"title": "Star Wars: Episode V - The Empire Strikes Back","synopsis": "After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda, while his friends are pursued across the galaxy by Darth Vader and bounty hunter Boba Fett.","actors": ["Mark Hamill", "Harrison Ford", "Carrie Fisher", "Billy Dee Williams"] ,"director":" Irvin Kershner ","rating":"8.7","certificate":"PG-13","genre": ["Action", "Adventure", "Fantasy"] } 36 | {"index":{"_index":"movies","_id":"18"}} 37 | {"title": "One Flew Over the Cuckoo's Nest","synopsis": "A criminal pleads insanity and is admitted to a mental institution, where he rebels against the oppressive nurse and rallies up the scared patients.","actors": ["Jack Nicholson", "Louise Fletcher", "Michael Berryman", "Peter Brocco"] ,"director":" Milos Forman ","rating":"8.7","certificate":"R","genre": "Drama" } 38 | {"index":{"_index":"movies","_id":"19"}} 39 | {"title": "Parasite","synopsis": "Greed and class discrimination threaten the newly formed symbiotic relationship between the wealthy Park family and the destitute Kim clan.","actors": ["Kang-ho Song", "Sun-kyun Lee", "Yeo-jeong Cho", "Woo-sik Choi"] ,"director":" Bong Joon Ho ","rating":"8.6","certificate":"R","genre": ["Comedy", "Drama", "Thriller"] } 40 | {"index":{"_index":"movies","_id":"20"}} 41 | {"title": "Interstellar","synopsis": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.","actors": ["Matthew McConaughey", "Anne Hathaway", "Jessica Chastain", "Mackenzie Foy"] ,"director":" Christopher Nolan ","rating":"8.6","certificate":"PG-13","genre": ["Adventure", "Drama", "Sci-Fi"] } 42 | {"index":{"_index":"movies","_id":"21"}} 43 | {"title": "City of God","synopsis": "In the slums of Rio, two kids paths diverge as one struggles to become a photographer and the other a kingpin.","actors": ["Alexandre Rodrigues", "Leandro Firmino", "Matheus Nachtergaele", "Phellipe Haagensen"] ,"director": ["Fernando Meirelles", "Kátia Lund"] ,"rating":"8.6","certificate":"R","genre": ["Crime", "Drama"] } 44 | {"index":{"_index":"movies","_id":"22"}} 45 | {"title": "Spirited Away","synopsis": "During her family's move to the suburbs, a sullen 10-year-old girl wanders into a world ruled by gods, witches, and spirits, and where humans are changed into beasts.","actors": ["Daveigh Chase", "Suzanne Pleshette", "Miyu Irino", "Rumi Hiiragi"] ,"director":" Hayao Miyazaki ","rating":"8.6","certificate":"PG-13","genre": ["Animation", "Adventure", "Family"]} 46 | {"index":{"_index":"movies","_id":"23"}} 47 | {"title": "Saving Private Ryan","synopsis": "Following the Normandy Landings, a group of U.S. soldiers go behind enemy lines to retrieve a paratrooper whose brothers have been killed in action.","actors": ["Tom Hanks", "Matt Damon", "Tom Sizemore", "Edward Burns"] ,"director":" Steven Spielberg ","rating":"8.6","certificate":"R","genre": ["Drama", "War"] } 48 | {"index":{"_index":"movies","_id":"24"}} 49 | {"title": "The Green Mile","synopsis": "The lives of guards on Death Row are affected by one of their charges: a black man accused of child murder and rape, yet who has a mysterious gift.","actors": ["Tom Hanks", "Michael Clarke Duncan", "David Morse", "Bonnie Hunt"] ,"director":" Frank Darabont ","rating":"8.6","certificate":"R","genre": ["Crime", "Drama", "Fantasy"] } 50 | {"index":{"_index":"movies","_id":"25"}} 51 | {"title": "Life Is Beautiful","synopsis": "When an open-minded Jewish librarian and his son become victims of the Holocaust, he uses a perfect mixture of will, humor, and imagination to protect his son from the dangers around their camp.","actors": ["Roberto Benigni", "Nicoletta Braschi", "Giorgio Cantarini", "Giustino Durano"] ,"director":" Roberto Benigni ","rating":"8.6","certificate":"PG-13","genre": ["Comedy", "Drama", "Romance"]} 52 | -------------------------------------------------------------------------------- /datasets/movies2.json: -------------------------------------------------------------------------------- 1 | POST _bulk 2 | {"index":{"_index":"movies","_id":"1"}} 3 | {"title": "The Shawshank Redemption","synopsis": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.","actors": ["Tim Robbins", "Morgan Freeman", "Bob Gunton", "William Sadler"] ,"director":" Frank Darabont ","rating":9.3,"certificate":"R","genre": "Drama "} 4 | {"index":{"_index":"movies","_id":"2"}} 5 | {"title": "The Godfather","synopsis": "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.","actors": ["Marlon Brando", "Al Pacino", "James Caan", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":9.2,"certificate":"R","genre": ["Crime", "Drama"] } 6 | {"index":{"_index":"movies","_id":"3"}} 7 | {"title": "The Dark Knight","synopsis": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, Batman must accept one of the greatest psychological and physical tests of his ability to fight injustice.","actors": ["Christian Bale", "Heath Ledger", "Aaron Eckhart", "Michael Caine"] ,"director":" Christopher Nolan ","rating":9.0,"certificate":"PG-13","genre": ["Action", "Crime", "Drama"] } 8 | {"index":{"_index":"movies","_id":"4"}} 9 | {"title": "The Godfather: Part II","synopsis": "The early life and career of Vito Corleone in 1920s New York City is portrayed, while his son, Michael, expands and tightens his grip on the family crime syndicate.","actors": ["Al Pacino", "Robert De Niro", "Robert Duvall", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":9.0,"certificate":"R","genre": ["Crime", "Drama"] } 10 | {"index":{"_index":"movies","_id":"5"}} 11 | {"title": "12 Angry Men","synopsis": "A jury holdout attempts to prevent a miscarriage of justice by forcing his colleagues to reconsider the evidence.","actors": ["Henry Fonda", "Lee J. Cobb", "Martin Balsam", " John Fiedler"] ,"director":" Sidney Lumet ","rating":9.0,"certificate":"Approved","genre": ["Crime", "Drama"] } 12 | {"index":{"_index":"movies","_id":"6"}} 13 | {"title": "The Lord of the Rings: The Return of the King","synopsis": "Gandalf and Aragorn lead the World of Men against Saurons's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring.","actors": ["Elijah Wood", "Viggo Mortensen", "Ian McKellen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":8.9,"certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] } 14 | {"index":{"_index":"movies","_id":"7"}} 15 | {"title": "Pulp Fiction","synopsis": "The lives of two mob hitmen, a boxer, a gangster and his wife, and a pair of diner bandits intertwine in four tales of violence and redemption.","actors": ["John Travolta", "Uma Thurman", "Samuel L. Jackson", "Bruce Willis"] ,"director":" Quentin Tarantino ","rating":8.9,"certificate":"R","genre": ["Crime", "Drama"] } 16 | {"index":{"_index":"movies","_id":"8"}} 17 | {"title": "Schindler's List","synopsis": "In German-occupied Poland during World War II, industrialist Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis.","actors": ["Liam Neeson", "Ralph Fiennes", "Ben Kingsley", "Caroline Goodall"] ,"director":" Steven Spielberg ","rating":8.9,"certificate":"R","genre": ["Biography", "Drama", "History"] } 18 | {"index":{"_index":"movies","_id":"9"}} 19 | {"title": "Inception","synopsis": "A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.","actors": ["Leonardo DiCaprio", "Joseph Gordon-Levitt", "Elliot Page", "Ken Watanabe"] ,"director":" Christopher Nolan ","rating":8.8,"certificate":"PG-13","genre": ["Action", "Adventure", "Sci-Fi"] } 20 | {"index":{"_index":"movies","_id":"10"}} 21 | {"title": "Fight Club","synopsis": "An insomniac office worker and a devil-may-care soap maker form an underground fight club that evolves into much more.","actors": ["Brad Pitt", "Edward Norton", "Meat Loaf", "Zach Grenier"] ,"director":" David Fincher ","rating":8.8,"certificate":"R","genre": "Drama"} 22 | {"index":{"_index":"movies","_id":"11"}} 23 | {"title": "The Lord of the Rings: The Fellowship of the Ring","synopsis": "A meek Hobbit from the Shire and eight companions set out on a journey to destroy the powerful One Ring and save Middle-earth from the Dark Lord Sauron.","actors": ["Elijah Wood", "Ian McKellen", "Orlando Bloom", "Sean Bean"] ,"director":" Peter Jackson ","rating":8.8,"certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] } 24 | {"index":{"_index":"movies","_id":"12"}} 25 | {"title": "Forrest Gump","synopsis": "The presidencies of Kennedy and Johnson, the Vietnam War, the Watergate scandal and other historical events unfold from the perspective of an Alabama man with an IQ of 75, whose only desire is to be reunited with his childhood sweetheart.","actors": ["Tom Hanks", "Robin Wright", "Gary Sinise", "Sally Field"] ,"director":" Robert Zemeckis ","rating":8.8,"certificate":"PG-13","genre": ["Drama", "Romance"] } 26 | {"index":{"_index":"movies","_id":"13"}} 27 | {"title": "The Good, the Bad and the Ugly","synopsis": "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.","actors": ["Clint Eastwood", "Eli Wallach", "Lee Van Cleef", "Aldo Giuffrè"] ,"director":" Sergio Leone ","rating":8.8,"certificate":"R","genre": "Western"} 28 | {"index":{"_index":"movies","_id":"14"}} 29 | {"title": "The Lord of the Rings: The Two Towers","synopsis": "While Frodo and Sam edge closer to Mordor with the help of the shifty Gollum, the divided fellowship makes a stand against Sauron's new ally, Saruman, and his hordes of Isengard.","actors": ["Elijah Wood", "Ian McKellen", "Viggo Mortensen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":8.7,"certificate":"PG-13","genre": ["Action", "Adventure", "Drama"]} 30 | {"index":{"_index":"movies","_id":"15"}} 31 | {"title": "The Matrix","synopsis": "When a beautiful stranger leads computer hacker Neo to a forbidding underworld, he discovers the shocking truth--the life he knows is the elaborate deception of an evil cyber-intelligence.","actors": ["Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss", "Hugo Weaving"] ,"director":["Lana Wachowski", "Lilly Wachowski"] ,"rating":8.7,"certificate":"R","genre": ["Action", "Sci-Fi"] } 32 | {"index":{"_index":"movies","_id":"16"}} 33 | {"title": "Goodfellas","synopsis": "The story of Henry Hill and his life in the mob, covering his relationship with his wife Karen Hill and his mob partners Jimmy Conway and Tommy DeVito in the Italian-American crime syndicate.","actors": ["Robert De Niro", "Ray Liotta", "Joe Pesci", "Lorraine Bracco"] ,"director":" Martin Scorsese ","rating":8.7,"certificate":"R","genre": ["Biography", "Drama", "Crime"] } 34 | {"index":{"_index":"movies","_id":"17"}} 35 | {"title": "Star Wars: Episode V - The Empire Strikes Back","synopsis": "After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda, while his friends are pursued across the galaxy by Darth Vader and bounty hunter Boba Fett.","actors": ["Mark Hamill", "Harrison Ford", "Carrie Fisher", "Billy Dee Williams"] ,"director":" Irvin Kershner ","rating":8.7,"certificate":"PG-13","genre": ["Action", "Adventure", "Fantasy"] } 36 | {"index":{"_index":"movies","_id":"18"}} 37 | {"title": "One Flew Over the Cuckoo's Nest","synopsis": "A criminal pleads insanity and is admitted to a mental institution, where he rebels against the oppressive nurse and rallies up the scared patients.","actors": ["Jack Nicholson", "Louise Fletcher", "Michael Berryman", "Peter Brocco"] ,"director":" Milos Forman ","rating":8.7,"certificate":"R","genre": "Drama" } 38 | {"index":{"_index":"movies","_id":"19"}} 39 | {"title": "Parasite","synopsis": "Greed and class discrimination threaten the newly formed symbiotic relationship between the wealthy Park family and the destitute Kim clan.","actors": ["Kang-ho Song", "Sun-kyun Lee", "Yeo-jeong Cho", "Woo-sik Choi"] ,"director":" Bong Joon Ho ","rating":8.6,"certificate":"R","genre": ["Comedy", "Drama", "Thriller"] } 40 | {"index":{"_index":"movies","_id":"20"}} 41 | {"title": "Interstellar","synopsis": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.","actors": ["Matthew McConaughey", "Anne Hathaway", "Jessica Chastain", "Mackenzie Foy"] ,"director":" Christopher Nolan ","rating":8.6,"certificate":"PG-13","genre": ["Adventure", "Drama", "Sci-Fi"] } 42 | {"index":{"_index":"movies","_id":"21"}} 43 | {"title": "City of God","synopsis": "In the slums of Rio, two kids paths diverge as one struggles to become a photographer and the other a kingpin.","actors": ["Alexandre Rodrigues", "Leandro Firmino", "Matheus Nachtergaele", "Phellipe Haagensen"] ,"director": ["Fernando Meirelles", "Kátia Lund"] ,"rating":8.6,"certificate":"R","genre": ["Crime", "Drama"] } 44 | {"index":{"_index":"movies","_id":"22"}} 45 | {"title": "Spirited Away","synopsis": "During her family's move to the suburbs, a sullen 10-year-old girl wanders into a world ruled by gods, witches, and spirits, and where humans are changed into beasts.","actors": ["Daveigh Chase", "Suzanne Pleshette", "Miyu Irino", "Rumi Hiiragi"] ,"director":" Hayao Miyazaki ","rating":8.6,"certificate":"PG-13","genre": ["Animation", "Adventure", "Family"]} 46 | {"index":{"_index":"movies","_id":"23"}} 47 | {"title": "Saving Private Ryan","synopsis": "Following the Normandy Landings, a group of U.S. soldiers go behind enemy lines to retrieve a paratrooper whose brothers have been killed in action.","actors": ["Tom Hanks", "Matt Damon", "Tom Sizemore", "Edward Burns"] ,"director":" Steven Spielberg ","rating":8.6,"certificate":"R","genre": ["Drama", "War"] } 48 | {"index":{"_index":"movies","_id":"24"}} 49 | {"title": "The Green Mile","synopsis": "The lives of guards on Death Row are affected by one of their charges: a black man accused of child murder and rape, yet who has a mysterious gift.","actors": ["Tom Hanks", "Michael Clarke Duncan", "David Morse", "Bonnie Hunt"] ,"director":" Frank Darabont ","rating":8.6,"certificate":"R","genre": ["Crime", "Drama", "Fantasy"] } 50 | {"index":{"_index":"movies","_id":"25"}} 51 | {"title": "Life Is Beautiful","synopsis": "When an open-minded Jewish librarian and his son become victims of the Holocaust, he uses a perfect mixture of will, humor, and imagination to protect his son from the dangers around their camp.","actors": ["Roberto Benigni", "Nicoletta Braschi", "Giorgio Cantarini", "Giustino Durano"] ,"director":" Roberto Benigni ","rating":8.6,"certificate":"PG-13","genre": ["Comedy", "Drama", "Romance"]} 52 | -------------------------------------------------------------------------------- /datasets/products2.txt: -------------------------------------------------------------------------------- 1 | PUT _bulk 2 | {"index":{"_index":"products2","_id":"1"}} 3 | {"product": "TV", "brand": "Samsung", "model": "UE75TU7020", "size": "75", "resolution": "4k", "type": "smart tv", "price": 799, "colour": "silver", "energy_rating": "A+", "overview": "Amazing 75-inch Samsung smart TV. The incredibly sharp 4K Ultra HD display shows off everything in breathtaking quality, with bright, lifelike colours truly immersing you in the action.","tech_spec":"smart tv;4k ultra hd;2 years warranty", "user_ratings": 4.5, "images": ""} 4 | {"index":{"_index":"products2","_id":"2"}} 5 | {"product": "TV", "brand": "Samsung", "model": "QE65Q700TA", "size": "65", "resolution": "8k", "type": "QLED", "price": 1799, "colour": "black", "energy_rating": "A+", "overview": "This outstanding 65-inch Samsung TV turns your living room into a home cinema with truly amazing tech. Its 8K QLED screen gives you an incredible razor-sharp picture bursting with ultra-realistic detail and bright, true-to-life colours.Of course, it's a smart TV too,", "tech_spec":"smart tv;8k QLED GD;3 years warranty", "user_ratings": 5, "images": ""} 6 | {"index":{"_index":"products2","_id":"3"}} 7 | {"product": "TV", "brand": "Sony", "model": "KD65AG8BU", "size": "65", "resolution": "4k", "type": "OLED", "price": 1699, "colour": "black", "energy_rating": "A+", "overview": "Bring the cinema into your home with this 65-inch Sony Bravia OLED TV. Images are upscaled for truer 4K HDR quality. OLED technology provides genuine black and sharp contrast", "tech_spec":"smart tv;OLED hd;5 years warranty", "user_ratings": 4.8, "images": ""} 8 | -------------------------------------------------------------------------------- /datasets/products_mapping.txt: -------------------------------------------------------------------------------- 1 | PUT products 2 | { 3 | "mappings": { 4 | "properties": { 5 | "brand": { 6 | "type": "text", 7 | "fields": { 8 | "keyword": { 9 | "type": "keyword", 10 | "ignore_above": 256 11 | } 12 | } 13 | }, 14 | "colour": { 15 | "type": "text", 16 | "fields": { 17 | "keyword": { 18 | "type": "keyword", 19 | "ignore_above": 256 20 | } 21 | } 22 | }, 23 | "energy_rating": { 24 | "type": "text", 25 | "fields": { 26 | "keyword": { 27 | "type": "keyword", 28 | "ignore_above": 256 29 | } 30 | } 31 | }, 32 | "images": { 33 | "type": "text" 34 | }, 35 | "model": { 36 | "type": "text", 37 | "fields": { 38 | "keyword": { 39 | "type": "keyword", 40 | "ignore_above": 256 41 | } 42 | } 43 | }, 44 | "overview": { 45 | "type": "text", 46 | "fields": { 47 | "keyword": { 48 | "type": "keyword", 49 | "ignore_above": 256 50 | } 51 | } 52 | }, 53 | "price": { 54 | "type": "double" 55 | }, 56 | "product": { 57 | "type": "text", 58 | "fields": { 59 | "keyword": { 60 | "type": "keyword", 61 | "ignore_above": 256 62 | } 63 | } 64 | }, 65 | "resolution": { 66 | "type": "text", 67 | "fields": { 68 | "keyword": { 69 | "type": "keyword", 70 | "ignore_above": 256 71 | } 72 | } 73 | }, 74 | "size": { 75 | "type": "text" 76 | }, 77 | "type": { 78 | "type": "text", 79 | "fields": { 80 | "keyword": { 81 | "type": "keyword", 82 | "ignore_above": 256 83 | } 84 | } 85 | }, 86 | "user_ratings": { 87 | "type": "double" 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /datasets/restaurants.txt: -------------------------------------------------------------------------------- 1 | # Create a mapping for restaurants 2 | PUT restaurants 3 | { 4 | "mappings": { 5 | "properties": { 6 | "name":{ 7 | "type": "text" 8 | }, 9 | "town_centre":{ 10 | "type": "geo_point" 11 | }, 12 | "location":{ 13 | "type": "geo_point" 14 | }, 15 | "category":{ 16 | "type":"text" 17 | }, 18 | "hygenie_rating":{ 19 | "type": "short" 20 | }, 21 | "borough":{ 22 | "type":"text" 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /datasets/three-books-kibana.txt: -------------------------------------------------------------------------------- 1 | PUT books/_doc/1 2 | { 3 | "title":"Effective Java", 4 | "author":"Joshua Bloch", 5 | "release_date":"2001-06-01", 6 | "amazon_rating":4.7, 7 | "best_seller":true, 8 | "prices": { 9 | "usd":9.95, 10 | "gbp":7.95, 11 | "eur":8.95 12 | } 13 | } 14 | 15 | PUT books/_doc/2 16 | { 17 | "title":"Core Java Volume I - Fundamentals", 18 | "author":"Cay S. Horstmann", 19 | "release_date":"2018-08-27", 20 | "amazon_rating":4.8, 21 | "best_seller":true, 22 | "prices": { 23 | "usd":19.95, 24 | "gbp":17.95, 25 | "eur":18.95 26 | } 27 | } 28 | 29 | PUT books/_doc/3 30 | { 31 | "title":"Java: A Beginner’s Guide", 32 | "author":"Herbert Schildt", 33 | "release_date":"2018-11-20", 34 | "amazon_rating":4.2, 35 | "best_seller":true, 36 | "prices": { 37 | "usd":19.99, 38 | "gbp":19.99, 39 | "eur":19.99 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /datasets/top-movies-kibana.txt: -------------------------------------------------------------------------------- 1 | POST _bulk 2 | {"index":{"_index":"movies","_id":"1"}} 3 | {"title": "The Shawshank Redemption","synopsis": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.","actors": ["Tim Robbins", "Morgan Freeman", "Bob Gunton", "William Sadler"] ,"director":" Frank Darabont ","rating":"9.3","certificate":"R","genre": "Drama "} 4 | {"index":{"_index":"movies","_id":"2"}} 5 | {"title": "The Godfather","synopsis": "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.","actors": ["Marlon Brando", "Al Pacino", "James Caan", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":"9.2","certificate":"R","genre": ["Crime", "Drama"] } 6 | {"index":{"_index":"movies","_id":"3"}} 7 | {"title": "The Dark Knight","synopsis": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, Batman must accept one of the greatest psychological and physical tests of his ability to fight injustice.","actors": ["Christian Bale", "Heath Ledger", "Aaron Eckhart", "Michael Caine"] ,"director":" Christopher Nolan ","rating":"9.0","certificate":"PG-13","genre": ["Action", "Crime", "Drama"] } 8 | {"index":{"_index":"movies","_id":"4"}} 9 | {"title": "The Godfather: Part II","synopsis": "The early life and career of Vito Corleone in 1920s New York City is portrayed, while his son, Michael, expands and tightens his grip on the family crime syndicate.","actors": ["Al Pacino", "Robert De Niro", "Robert Duvall", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":"9.0","certificate":"R","genre": ["Crime", "Drama"] } 10 | {"index":{"_index":"movies","_id":"5"}} 11 | {"title": "12 Angry Men","synopsis": "A jury holdout attempts to prevent a miscarriage of justice by forcing his colleagues to reconsider the evidence.","actors": ["Henry Fonda", "Lee J. Cobb", "Martin Balsam", " John Fiedler"] ,"director":" Sidney Lumet ","rating":"9.0","certificate":"Approved","genre": ["Crime", "Drama"] } 12 | {"index":{"_index":"movies","_id":"6"}} 13 | {"title": "The Lord of the Rings: The Return of the King","synopsis": "Gandalf and Aragorn lead the World of Men against Saurons's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring.","actors": ["Elijah Wood", "Viggo Mortensen", "Ian McKellen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":"8.9","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] } 14 | {"index":{"_index":"movies","_id":"7"}} 15 | {"title": "Pulp Fiction","synopsis": "The lives of two mob hitmen, a boxer, a gangster and his wife, and a pair of diner bandits intertwine in four tales of violence and redemption.","actors": ["John Travolta", "Uma Thurman", "Samuel L. Jackson", "Bruce Willis"] ,"director":" Quentin Tarantino ","rating":"8.9","certificate":"R","genre": ["Crime", "Drama"] } 16 | {"index":{"_index":"movies","_id":"8"}} 17 | {"title": "Schindler's List","synopsis": "In German-occupied Poland during World War II, industrialist Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis.","actors": ["Liam Neeson", "Ralph Fiennes", "Ben Kingsley", "Caroline Goodall"] ,"director":" Steven Spielberg ","rating":"8.9","certificate":"R","genre": ["Biography", "Drama", "History"] } 18 | {"index":{"_index":"movies","_id":"9"}} 19 | {"title": "Inception","synopsis": "A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.","actors": ["Leonardo DiCaprio", "Joseph Gordon-Levitt", "Elliot Page", "Ken Watanabe"] ,"director":" Christopher Nolan ","rating":"8.8","certificate":"PG-13","genre": ["Action", "Adventure", "Sci-Fi"] } 20 | {"index":{"_index":"movies","_id":"10"}} 21 | {"title": "Fight Club","synopsis": "An insomniac office worker and a devil-may-care soap maker form an underground fight club that evolves into much more.","actors": ["Brad Pitt", "Edward Norton", "Meat Loaf", "Zach Grenier"] ,"director":" David Fincher ","rating":"8.8","certificate":"R","genre": "Drama"} 22 | {"index":{"_index":"movies","_id":"11"}} 23 | {"title": "The Lord of the Rings: The Fellowship of the Ring","synopsis": "A meek Hobbit from the Shire and eight companions set out on a journey to destroy the powerful One Ring and save Middle-earth from the Dark Lord Sauron.","actors": ["Elijah Wood", "Ian McKellen", "Orlando Bloom", "Sean Bean"] ,"director":" Peter Jackson ","rating":"8.8","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] } 24 | {"index":{"_index":"movies","_id":"12"}} 25 | {"title": "Forrest Gump","synopsis": "The presidencies of Kennedy and Johnson, the Vietnam War, the Watergate scandal and other historical events unfold from the perspective of an Alabama man with an IQ of 75, whose only desire is to be reunited with his childhood sweetheart.","actors": ["Tom Hanks", "Robin Wright", "Gary Sinise", "Sally Field"] ,"director":" Robert Zemeckis ","rating":"8.8","certificate":"PG-13","genre": ["Drama", "Romance"] } 26 | {"index":{"_index":"movies","_id":"13"}} 27 | {"title": "The Good, the Bad and the Ugly","synopsis": "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.","actors": ["Clint Eastwood", "Eli Wallach", "Lee Van Cleef", "Aldo Giuffrè"] ,"director":" Sergio Leone ","rating":"8.8","certificate":"R","genre": "Western"} 28 | {"index":{"_index":"movies","_id":"14"}} 29 | {"title": "The Lord of the Rings: The Two Towers","synopsis": "While Frodo and Sam edge closer to Mordor with the help of the shifty Gollum, the divided fellowship makes a stand against Sauron's new ally, Saruman, and his hordes of Isengard.","actors": ["Elijah Wood", "Ian McKellen", "Viggo Mortensen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":"8.7","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"]} 30 | {"index":{"_index":"movies","_id":"15"}} 31 | {"title": "The Matrix","synopsis": "When a beautiful stranger leads computer hacker Neo to a forbidding underworld, he discovers the shocking truth--the life he knows is the elaborate deception of an evil cyber-intelligence.","actors": ["Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss", "Hugo Weaving"] ,"director":["Lana Wachowski", "Lilly Wachowski"] ,"rating":"8.7","certificate":"R","genre": ["Action", "Sci-Fi"] } 32 | {"index":{"_index":"movies","_id":"16"}} 33 | {"title": "Goodfellas","synopsis": "The story of Henry Hill and his life in the mob, covering his relationship with his wife Karen Hill and his mob partners Jimmy Conway and Tommy DeVito in the Italian-American crime syndicate.","actors": ["Robert De Niro", "Ray Liotta", "Joe Pesci", "Lorraine Bracco"] ,"director":" Martin Scorsese ","rating":"8.7","certificate":"R","genre": ["Biography", "Drama", "Crime"] } 34 | {"index":{"_index":"movies","_id":"17"}} 35 | {"title": "Star Wars: Episode V - The Empire Strikes Back","synopsis": "After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda, while his friends are pursued across the galaxy by Darth Vader and bounty hunter Boba Fett.","actors": ["Mark Hamill", "Harrison Ford", "Carrie Fisher", "Billy Dee Williams"] ,"director":" Irvin Kershner ","rating":"8.7","certificate":"PG-13","genre": ["Action", "Adventure", "Fantasy"] } 36 | {"index":{"_index":"movies","_id":"18"}} 37 | {"title": "One Flew Over the Cuckoo's Nest","synopsis": "A criminal pleads insanity and is admitted to a mental institution, where he rebels against the oppressive nurse and rallies up the scared patients.","actors": ["Jack Nicholson", "Louise Fletcher", "Michael Berryman", "Peter Brocco"] ,"director":" Milos Forman ","rating":"8.7","certificate":"R","genre": "Drama" } 38 | {"index":{"_index":"movies","_id":"19"}} 39 | {"title": "Parasite","synopsis": "Greed and class discrimination threaten the newly formed symbiotic relationship between the wealthy Park family and the destitute Kim clan.","actors": ["Kang-ho Song", "Sun-kyun Lee", "Yeo-jeong Cho", "Woo-sik Choi"] ,"director":" Bong Joon Ho ","rating":"8.6","certificate":"R","genre": ["Comedy", "Drama", "Thriller"] } 40 | {"index":{"_index":"movies","_id":"20"}} 41 | {"title": "Interstellar","synopsis": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.","actors": ["Matthew McConaughey", "Anne Hathaway", "Jessica Chastain", "Mackenzie Foy"] ,"director":" Christopher Nolan ","rating":"8.6","certificate":"PG-13","genre": ["Adventure", "Drama", "Sci-Fi"] } 42 | {"index":{"_index":"movies","_id":"21"}} 43 | {"title": "City of God","synopsis": "In the slums of Rio, two kids paths diverge as one struggles to become a photographer and the other a kingpin.","actors": ["Alexandre Rodrigues", "Leandro Firmino", "Matheus Nachtergaele", "Phellipe Haagensen"] ,"director": ["Fernando Meirelles", "Kátia Lund"] ,"rating":"8.6","certificate":"R","genre": ["Crime", "Drama"] } 44 | {"index":{"_index":"movies","_id":"22"}} 45 | {"title": "Spirited Away","synopsis": "During her family's move to the suburbs, a sullen 10-year-old girl wanders into a world ruled by gods, witches, and spirits, and where humans are changed into beasts.","actors": ["Daveigh Chase", "Suzanne Pleshette", "Miyu Irino", "Rumi Hiiragi"] ,"director":" Hayao Miyazaki ","rating":"8.6","certificate":"PG-13","genre": ["Animation", "Adventure", "Family"]} 46 | {"index":{"_index":"movies","_id":"23"}} 47 | {"title": "Saving Private Ryan","synopsis": "Following the Normandy Landings, a group of U.S. soldiers go behind enemy lines to retrieve a paratrooper whose brothers have been killed in action.","actors": ["Tom Hanks", "Matt Damon", "Tom Sizemore", "Edward Burns"] ,"director":" Steven Spielberg ","rating":"8.6","certificate":"R","genre": ["Drama", "War"] } 48 | {"index":{"_index":"movies","_id":"24"}} 49 | {"title": "The Green Mile","synopsis": "The lives of guards on Death Row are affected by one of their charges: a black man accused of child murder and rape, yet who has a mysterious gift.","actors": ["Tom Hanks", "Michael Clarke Duncan", "David Morse", "Bonnie Hunt"] ,"director":" Frank Darabont ","rating":"8.6","certificate":"R","genre": ["Crime", "Drama", "Fantasy"] } 50 | {"index":{"_index":"movies","_id":"25"}} 51 | {"title": "Life Is Beautiful","synopsis": "When an open-minded Jewish librarian and his son become victims of the Holocaust, he uses a perfect mixture of will, humor, and imagination to protect his son from the dangers around their camp.","actors": ["Roberto Benigni", "Nicoletta Braschi", "Giorgio Cantarini", "Giustino Durano"] ,"director":" Roberto Benigni ","rating":"8.6","certificate":"PG-13","genre": ["Comedy", "Drama", "Romance"]} 52 | -------------------------------------------------------------------------------- /datasets/tv_sales.txt: -------------------------------------------------------------------------------- 1 | PUT tv_sales/_bulk 2 | {"index":{"_id":"1"}} 3 | {"brand": "Samsung","name":"UHD TV","size_inches":65,"price_gbp":1400,"sales":17} 4 | {"index":{"_id":"2"}} 5 | {"brand":"Samsung","name":"UHD TV","size_inches":45,"price_gbp":1000,"sales":11} 6 | {"index":{"_id":"3"}} 7 | {"brand":"Samsung","name":"UHD TV","size_inches":23,"price_gbp":999,"sales":14} 8 | {"index":{"_id":"4"}} 9 | {"brand":"LG","name":"8K TV","size_inches":65,"price_gbp":1499,"sales":13} 10 | {"index":{"_id":"5"}} 11 | { "brand":"LG","name":"4K TV","size_inches":55,"price_gbp":1100,"sales":31} 12 | {"index":{"_id":"6"}} 13 | {"brand":"Philips","name":"8K TV","size_inches":65,"price_gbp":1800,"sales":23} 14 | {"index":{"_id":"7"}} 15 | {"brand":"Philips","name":"8K TV","size_inches":65,"price_gbp":2000,"sales":23} 16 | {"index":{"_id":"9"}} 17 | {"brand":"LG","name":"8K TV","size_inches":75,"price_gbp":2000,"sales":48,"best_seller":true} 18 | {"index":{"_id":"10"}} 19 | {"brand":"Panasonic", "name":"4K TV","size_inches":75,"price_gbp":2200,"sales":14,"best_seller":false} 20 | -------------------------------------------------------------------------------- /datasets/vector-search-sample.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "title": "Core Java Volume I – Fundamentals" 4 | }, 5 | { 6 | "title": "Effective Java" 7 | }, 8 | { 9 | "title": "Java: A Beginner’s Guid" 10 | }, 11 | { 12 | "title": "Java - The Complete Reference" 13 | }, 14 | { 15 | "title": "Head First Java" 16 | }, 17 | { 18 | "title": "Kibana 4 Video Tutorials, Part 3" 19 | }, 20 | { 21 | "title": "Keeping up with Kibana: This week in Kibana for November 29th, 2019" 22 | }, 23 | { 24 | "title": "London Bridge" 25 | } 26 | 27 | ] 28 | -------------------------------------------------------------------------------- /docker/7.15.1_es_kibana.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | elasticsearch: 4 | image: docker.elastic.co/elasticsearch/elasticsearch:7.15.1 5 | container_name: elasticsearch-in-action-7.15.1 6 | environment: 7 | - node.name=node1 8 | - cluster.name=elasticsearch-in-action 9 | - discovery.type=single-node 10 | - bootstrap.memory_lock=true 11 | - path.repo=/usr/share/elasticsearch/backups 12 | - ES_JAVA_OPTS=-Xms512m -Xmx512m 13 | ulimits: 14 | memlock: 15 | soft: -1 16 | hard: -1 17 | volumes: 18 | - node1-data:/usr/share/elasticsearch/data 19 | ports: 20 | - 9200:9200 21 | networks: 22 | - elasticsearch-in-action 23 | kibana: 24 | image: docker.elastic.co/kibana/kibana:7.15.1 25 | container_name: kibana-7.15.1 26 | environment: 27 | - elasticsearch.url=http://elasticsearch:9200 28 | ulimits: 29 | memlock: 30 | soft: -1 31 | hard: -1 32 | ports: 33 | - 5601:5601 34 | networks: 35 | - elasticsearch-in-action 36 | depends_on: 37 | - elasticsearch 38 | 39 | volumes: 40 | node1-data: 41 | driver: local 42 | 43 | networks: 44 | elasticsearch-in-action: 45 | -------------------------------------------------------------------------------- /docker/elasticsearch-docker-8-1-2.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | elasticsearch: 4 | image: docker.elastic.co/elasticsearch/elasticsearch:8.1.2 5 | container_name: elasticsearch-in-action-8.1.2 6 | environment: 7 | - node.name=node1 8 | - cluster.name=elasticsearch-in-action 9 | - discovery.type=single-node 10 | - bootstrap.memory_lock=true 11 | - xpack.security.enabled=false 12 | - path.repo=/usr/share/elasticsearch/backups 13 | - ES_JAVA_OPTS=-Xms512m -Xmx512m 14 | ulimits: 15 | memlock: 16 | soft: -1 17 | hard: -1 18 | volumes: 19 | - node1-data:/usr/share/elasticsearch/data 20 | ports: 21 | - 9200:9200 22 | networks: 23 | - elasticsearch-in-action 24 | kibana: 25 | image: docker.elastic.co/kibana/kibana:8.1.2 26 | container_name: kibana-in-action-8.1.2 27 | environment: 28 | - elasticsearch.url=http://elasticsearch:9200 29 | - csp.strict=false 30 | ulimits: 31 | memlock: 32 | soft: -1 33 | hard: -1 34 | ports: 35 | - 5601:5601 36 | networks: 37 | - elasticsearch-in-action 38 | depends_on: 39 | - elasticsearch 40 | 41 | volumes: 42 | node1-data: 43 | driver: local 44 | 45 | networks: 46 | elasticsearch-in-action: 47 | -------------------------------------------------------------------------------- /docker/elasticsearch-docker-8-6-2.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | elasticsearch: 4 | image: docker.elastic.co/elasticsearch/elasticsearch:8.6.2 5 | container_name: elasticsearch-in-action-8.6.2 6 | environment: 7 | - node.name=node1 8 | - cluster.name=elasticsearch-in-action 9 | - discovery.type=single-node 10 | - bootstrap.memory_lock=true 11 | - xpack.security.enabled=false 12 | - path.repo=/usr/share/elasticsearch/backups 13 | - ES_JAVA_OPTS=-Xms512m -Xmx512m 14 | ulimits: 15 | memlock: 16 | soft: -1 17 | hard: -1 18 | volumes: 19 | - node1-data:/usr/share/elasticsearch/data 20 | ports: 21 | - 9200:9200 22 | networks: 23 | - elasticsearch-in-action 24 | kibana: 25 | image: docker.elastic.co/kibana/kibana:8.6.2 26 | container_name: kibana-in-action-8.6.2 27 | environment: 28 | - elasticsearch.url=http://elasticsearch:9200 29 | - csp.strict=false 30 | ulimits: 31 | memlock: 32 | soft: -1 33 | hard: -1 34 | ports: 35 | - 5601:5601 36 | networks: 37 | - elasticsearch-in-action 38 | depends_on: 39 | - elasticsearch 40 | 41 | volumes: 42 | node1-data: 43 | driver: local 44 | 45 | networks: 46 | elasticsearch-in-action: 47 | -------------------------------------------------------------------------------- /docker/one_node_es.yml: -------------------------------------------------------------------------------- 1 | #One node elasticsearch 2 | 3 | -------------------------------------------------------------------------------- /docker/one_node_kibana.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /kibana_scripts/appendix_ingest_pipelines.txt: -------------------------------------------------------------------------------- 1 | # Ingest Pipelines 2 | 3 | # Create a pipeline that stamps incoming data with an additional field "confidential" 4 | PUT _ingest/pipeline/confidential_files_pipeline 5 | { 6 | "description": "Stamp confidential on the file (document)", 7 | "processors": [ 8 | { 9 | "set": { 10 | "field": "category", 11 | "value": "confidential" 12 | } 13 | } 14 | ] 15 | } 16 | 17 | POST _ingest/pipeline/confidential_files_pipeline/_simulate 18 | { 19 | "docs": [ 20 | { 21 | "_source": { 22 | "op_name": "Operation Cobra" 23 | } 24 | } 25 | ] 26 | } 27 | 28 | # Adding another processor to uppercase the newly created field: 29 | 30 | PUT _ingest/pipeline/confidential_files_pipeline 31 | { 32 | "description": "Stamp confidential on the file (document)", 33 | "processors": [ 34 | { 35 | "set": { 36 | "field": "category", 37 | "value": "confidential" 38 | }, 39 | "uppercase": { 40 | "field": "category" 41 | } 42 | } 43 | ] 44 | } 45 | 46 | # Testing the modified pipeline second time 47 | POST _ingest/pipeline/confidential_files_pipeline/_simulate 48 | { 49 | "docs": [ 50 | { 51 | "_source": { 52 | "op_name": "Operation Cobra" 53 | } 54 | } 55 | ] 56 | } 57 | 58 | # Create a pipeline that stamps incoming data with an additional field "confidential" 59 | PUT _ingest/pipeline/confidential_pdf_files_pipeline 60 | { 61 | "description": "Pipeline to load PDF documents", 62 | "processors": [ 63 | { 64 | "set": { 65 | "field": "category", 66 | "value": "confidential" 67 | }, 68 | "attachment": { 69 | "field": "secret_file_data" 70 | } 71 | } 72 | ] 73 | } 74 | 75 | 76 | POST _ingest/pipeline/confidential_pdf_files_pipeline/_simulate 77 | { 78 | "docs": [ 79 | { 80 | "_source": { 81 | "op_name": "Op Konda", 82 | "secret_file_data":"U3VuZGF5IEx1bmNoIGF0IEtvbmRhJ3M=" 83 | } 84 | } 85 | ] 86 | } 87 | 88 | # Choosing only content metadata as part of attachment 89 | 90 | PUT _ingest/pipeline/only_content_pdf_files_pipeline 91 | { 92 | "description": "Pipeline to load PDF documents", 93 | "processors": [ 94 | { 95 | "set": { 96 | "field": "category", 97 | "value": "confidential" 98 | }, 99 | "attachment": { 100 | "field": "secret_file_data", 101 | "properties":["content"] 102 | } 103 | } 104 | ] 105 | } 106 | 107 | # Testing the pipeline 108 | GET _ingest/pipeline/only_content_pdf_files_pipeline/_simulate 109 | { 110 | "docs": [ 111 | { 112 | "_source": { 113 | "op_name": "Op Konda", 114 | "secret_file_data":"U3VuZGF5IEx1bmNoIGF0IEtvbmRhJ3M=" 115 | } 116 | } 117 | ] 118 | } 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /kibana_scripts/ch02_getting_started.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## A handy scripts file for hands-on exercises on Kibana 3 | ## Copy the whole contents of this file to Kibana's DevTools 4 | 5 | ## If you wish to follow the running commentary for these scripts, 6 | ## follow the Ch2 Getting Started wiki page here: https://github.com/madhusudhankonda/elasticsearch-in-action/wiki/Ch-2:-Getting-Started 7 | ## 8 | ## Please let me know if you find any issues with this script 9 | 10 | 11 | 12 | # Indexing a few documents into books index 13 | PUT books/_doc/1 14 | { 15 | "title":"Effective Java", 16 | "author":"Joshua Bloch", 17 | "release_date":"2001-06-01", 18 | "amazon_rating":4.7, 19 | "best_seller":true, 20 | "prices": { 21 | "usd":9.95, 22 | "gbp":7.95, 23 | "eur":8.95 24 | } 25 | } 26 | PUT books/_doc/2 27 | { 28 | "title":"Core Java Volume I - Fundamentals", 29 | "author":"Cay S. Horstmann", 30 | "release_date":"2018-08-27", 31 | "amazon_rating":4.8, 32 | "best_seller":true, 33 | "prices": { 34 | "usd":19.95, 35 | "gbp":17.95, 36 | "eur":18.95 37 | } 38 | } 39 | PUT books/_doc/3 40 | { 41 | "title":"Java: A Beginner’s Guide", 42 | "author":"Herbert Schildt", 43 | "release_date":"2018-11-20", 44 | "amazon_rating":4.2, 45 | "best_seller":true, 46 | "prices": { 47 | "usd":19.99, 48 | "gbp":19.99, 49 | "eur":19.99 50 | } 51 | } 52 | 53 | #Getting number of documents in books index 54 | GET books/_count 55 | 56 | #Adding another index with a sample doc 57 | PUT fiction/_doc/1 58 | { 59 | "title":"The Enchanters' Child", 60 | "author":"Navya Sarikonda" 61 | } 62 | # Fetching all documents from multiple indices 63 | GET books,fiction/_count 64 | 65 | #Fetch from ALL indices 66 | GET /_count 67 | 68 | #You can also use a wildcard too 69 | GET b*/_count 70 | 71 | # Fetching the document by its ID 72 | GET books/_doc/1 73 | 74 | # To fetch source only 75 | GET books/_source/1 76 | 77 | # To fetch multiple documents give a set of IDs using ids query 78 | GET books/_search 79 | { 80 | "query": { 81 | "ids": { 82 | "values": [1,2,3] 83 | } 84 | } 85 | } 86 | # Turn off the source 87 | GET books/_search 88 | { 89 | "_source": false, 90 | "query": { 91 | "ids": { 92 | "values": [1,2,3] 93 | } 94 | } 95 | } 96 | # Retrieving all documents in one go from the books index 97 | GET books/_search 98 | 99 | # Searching for books by an author 100 | GET books/_search 101 | { 102 | "query": { 103 | "match": { 104 | "author": "Joshua" 105 | } 106 | } 107 | } 108 | 109 | # Search using different cased letters 110 | GET books/_search 111 | { 112 | "query": { 113 | "match": { 114 | "author": "JoShUa" 115 | } 116 | } 117 | } 118 | 119 | # Search using surname 120 | GET books/_search 121 | { 122 | "query": { 123 | "match": { 124 | "author": "Bloch" 125 | } 126 | } 127 | } 128 | 129 | # Searching like regex won't return retun results 130 | GET books/_search 131 | { 132 | "query": { 133 | "match": { 134 | "author": "Josh" 135 | } 136 | } 137 | } 138 | 139 | # Searching like regex with prefix query - make sure the criteria is lowercased 140 | GET books/_search 141 | { 142 | "query": { 143 | "prefix": { 144 | "author": "josh" 145 | } 146 | } 147 | } 148 | 149 | #Searching for different keywords will still bring the results 150 | GET books/_search 151 | { 152 | "query": { 153 | "match": { 154 | "author": { 155 | "query": "Joshua Sarikonda" 156 | } 157 | } 158 | } 159 | } 160 | GET books/_search 161 | { 162 | "query": { 163 | "match": { 164 | "author": "Joshua Schildt" 165 | } 166 | } 167 | } 168 | 169 | #Searching for different keywords with an operator 170 | GET books/_search 171 | { 172 | "query": { 173 | "match": { 174 | "author": { 175 | "query": "Joshua Herbert" 176 | } 177 | } 178 | } 179 | } 180 | 181 | GET books/_search 182 | { 183 | "query": { 184 | "match": { 185 | "author": { 186 | "query": "Joshua Herbert", 187 | "operator": "AND" 188 | } 189 | } 190 | } 191 | } 192 | 193 | # Indexing lots of documents using bulk API 194 | # Copy the contents of books-kibana-dataset.txt from book's repository(https://github.com/madhusudhankonda/elasticsearch-in-action/blob/main/datasets/books-kibana-dataset.txt) 195 | 196 | # Searching across multiple fields using multi_match query 197 | GET books/_search 198 | { 199 | "query": { 200 | "multi_match": { 201 | "query": "Java", 202 | "fields": ["title","synopsis"] 203 | } 204 | } 205 | } 206 | # Boosting scores 207 | GET books/_search 208 | { 209 | "query": { 210 | "multi_match": { 211 | "query": "Java", 212 | "fields": ["title^3","synopsis"] 213 | } 214 | } 215 | } 216 | # Phrase search 217 | GET books/_search 218 | { 219 | "query": { 220 | "match_phrase": {#A The match_phrase query expects a sequence of words 221 | "synopsis": "must-have book for every Java programmer"#B Our phrase 222 | } 223 | } 224 | } 225 | 226 | # Match Phrase query 227 | GET books/_search 228 | { 229 | "query": { 230 | "match_phrase": { 231 | "synopsis": "must-have book for every Java programmer" 232 | } 233 | } 234 | } 235 | 236 | # Match Phrase query with highlights 237 | GET books/_search 238 | { 239 | "query": { 240 | "match_phrase": { 241 | "synopsis": "must-have book for every Java programmer" 242 | } 243 | }, 244 | "highlight": { 245 | "fields": { 246 | "synopsis": {} 247 | } 248 | } 249 | } 250 | 251 | # Match Phrase query with a word missing - doesn't get results 252 | GET books/_search 253 | { 254 | "query": { 255 | "match_phrase": { 256 | "synopsis": "must-have book every Java programmer" 257 | } 258 | } 259 | } 260 | 261 | # Match Phrase query with slop 1 262 | GET books/_search 263 | { 264 | "query": { 265 | "match_phrase": { 266 | "synopsis": { 267 | "query": "must-have book every Java programmer", 268 | "slop": 1 269 | } 270 | } 271 | } 272 | } 273 | 274 | #Fuzzy query (forgiving spelling mistakes) 275 | GET books/_search 276 | { 277 | "query": { 278 | "fuzzy": { 279 | "title": { 280 | "value": "kava", 281 | "fuzziness": 1 282 | } 283 | } 284 | } 285 | } 286 | 287 | #Add few adhoc documents to the books index to run match_phrase_prefix query 288 | PUT books/_doc/99 289 | { 290 | "title":"Java Collections Deep Dive" 291 | } 292 | PUT books/_doc/100 293 | { 294 | "title":"Java Computing World" 295 | } 296 | 297 | GET books/_search 298 | { 299 | "query": { 300 | "match_phrase_prefix": { 301 | "title": "Java co" 302 | } 303 | } 304 | } 305 | 306 | ## TERM queries 307 | # Get the index mapping 308 | GET books/_mapping 309 | 310 | # Getting third edition books using term query 311 | GET books/_search 312 | { 313 | 314 | "query": { 315 | "term": { 316 | "edition": { 317 | "value": 3 318 | } 319 | } 320 | } 321 | } 322 | 323 | # Range query 324 | GET books/_search 325 | { 326 | "query": { 327 | "range": { 328 | "amazon_rating": { 329 | "gte": 4.5, 330 | "lte": 5 331 | } 332 | } 333 | } 334 | } 335 | 336 | ## Bool queries 337 | # Must clause with match query 338 | GET books/_search 339 | { 340 | "query": { 341 | "bool": { 342 | "must": [ 343 | { 344 | "match": { 345 | "author": "Joshua Bloch" 346 | } 347 | } 348 | ] 349 | } 350 | } 351 | } 352 | 353 | # Must clause with two leaf queries - match and match_phrase 354 | GET books/_search 355 | { 356 | "query": { 357 | "bool": { 358 | "must": [ 359 | { 360 | "match": { 361 | "author": "Joshua Bloch" 362 | } 363 | }, 364 | { 365 | "match_phrase": { 366 | "synopsis": "best Java programming books" 367 | } 368 | } 369 | ] 370 | } 371 | } 372 | } 373 | 374 | # Must and must_not clauses 375 | GET books/_search 376 | { 377 | "query": { 378 | "bool": { 379 | "must": [ 380 | { 381 | "match": { 382 | "author": "Joshua" 383 | } 384 | } 385 | ], 386 | "must_not": [ 387 | { 388 | "range": { 389 | "amazon_rating": { 390 | "lt": 4.7 391 | } 392 | } 393 | } 394 | ] 395 | } 396 | } 397 | } 398 | 399 | # Must, must_not and should clauses 400 | GET books/_search 401 | { 402 | "query": { 403 | "bool": { 404 | "must": [ 405 | { 406 | "match": { 407 | "author": "Joshua" 408 | } 409 | } 410 | ], 411 | "must_not": [ 412 | { 413 | "range": { 414 | "amazon_rating": { 415 | "lt": 4.7 416 | } 417 | } 418 | } 419 | ], 420 | "should": [ 421 | { 422 | "match": { 423 | "tags": "Software" 424 | } 425 | } 426 | ] 427 | } 428 | } 429 | } 430 | 431 | # Should clause without a match - the query will not fail 432 | GET books/_search 433 | { 434 | "query": { 435 | "bool": { 436 | "must": [ 437 | { 438 | "match": { 439 | "author": "Joshua" 440 | } 441 | } 442 | ], 443 | "must_not": [ 444 | { 445 | "range": { 446 | "amazon_rating": { 447 | "lt": 4.7 448 | } 449 | } 450 | } 451 | ], 452 | "should": [ 453 | { 454 | "match": { 455 | "tags": "movies" 456 | } 457 | } 458 | ] 459 | } 460 | } 461 | } 462 | 463 | # Adding a filter clause - drops books older than 2015 464 | GET books/_search 465 | { 466 | "query": { 467 | "bool": { 468 | "must": [ 469 | { 470 | "match": { 471 | "author": "Joshua" 472 | } 473 | } 474 | ], 475 | "must_not": [ 476 | { 477 | "range": { 478 | "amazon_rating": { 479 | "lt": 4.7 480 | } 481 | } 482 | } 483 | ], 484 | "should": [ 485 | { 486 | "match": { 487 | "tags": "Software" 488 | } 489 | } 490 | ], 491 | "filter": [ 492 | { 493 | "range": { 494 | "release_date": { 495 | "gte": "2015-01-01" 496 | } 497 | } 498 | } 499 | ] 500 | } 501 | } 502 | } 503 | 504 | # Adding a filter clause - drops books older than 2015 505 | GET books/_search 506 | { 507 | "query": { 508 | "bool": { 509 | "must": [ 510 | { 511 | "match": { 512 | "author": "Joshua" 513 | } 514 | } 515 | ], 516 | "must_not": [ 517 | { 518 | "range": { 519 | "amazon_rating": { 520 | "lt": 4.7 521 | } 522 | } 523 | } 524 | ], 525 | "should": [ 526 | { 527 | "match": { 528 | "tags": "Software" 529 | } 530 | } 531 | ], 532 | "filter": [ 533 | { 534 | "range": { 535 | "release_date": { 536 | "gte": "2015-01-01" 537 | } 538 | } 539 | }, 540 | { 541 | "term": { 542 | "edition": 3 543 | } 544 | } 545 | ] 546 | } 547 | } 548 | } 549 | 550 | # Adding a second filter (term query to check the edition ) 551 | GET books/_search 552 | { 553 | "query": { 554 | "bool": { 555 | "must": [{"match": {"author": "Joshua"}}], 556 | "must_not":[{"range":{"amazon_rating":{"lt":4.7}}}], 557 | "should": [{"match": {"tags": "Software"}}], 558 | "filter":[ 559 | {"range":{"release_date":{"gte": "2015-01-01"}}}, 560 | {"term": {"edition": 3}} 561 | ]} 562 | } 563 | } 564 | #Analytics 565 | ## Average rating of books - Query DSL sample 566 | GET books/_search 567 | { 568 | "aggs": { 569 | "avg_rating": { 570 | "avg": { 571 | "field": "amazon_rating" 572 | } 573 | } 574 | } 575 | } 576 | 577 | ## Copy the contents of covid-26march2021.txt from datasets (https://github.com/madhusudhankonda/elasticsearch-in-action/blob/main/datasets/covid-26march2021.txt) to Kibana's DevTools. Once copied, execute them using the _bulk API 578 | 579 | # Sum metric 580 | GET covid/_search 581 | { 582 | "size": 0, 583 | "aggs": { 584 | "critical_patients": { 585 | "sum": { 586 | "field": "critical" 587 | } 588 | } 589 | } 590 | } 591 | 592 | # Max metric 593 | GET covid/_search 594 | { 595 | "size": 0, 596 | "aggs": { 597 | "total_deaths": { 598 | "max": { 599 | "field": "deaths" 600 | } 601 | } 602 | } 603 | } 604 | 605 | #Stats metric 606 | GET covid/_search 607 | { 608 | "size": 0, 609 | "aggs": { 610 | "all_stats": { 611 | "stats": { 612 | "field": "deaths" 613 | } 614 | } 615 | } 616 | } 617 | 618 | #Extended stats 619 | GET covid/_search 620 | { 621 | "aggs": { 622 | "all_extended_stats": { 623 | "extended_stats": { 624 | "field": "deaths" 625 | } 626 | } 627 | } 628 | } 629 | 630 | #Bucketing aggreations 631 | 632 | ## Histogram 633 | 634 | GET covid/_search 635 | { 636 | "size": 0, 637 | "aggs": { 638 | "critical_patients_as_histogram": { 639 | "histogram": { 640 | "field": "critical", 641 | "interval": 2500 642 | } 643 | } 644 | } 645 | } 646 | 647 | #Range 648 | GET covid/_search 649 | { 650 | "size": 0, 651 | "aggs": { 652 | "range_countries": { 653 | "range": { 654 | "field": "deaths", 655 | "ranges": [ 656 | {"to": 60000}, 657 | {"from": 60000,"to": 70000}, 658 | {"from": 70000,"to": 80000}, 659 | {"from": 80000,"to": 120000} 660 | ] 661 | } 662 | } 663 | } 664 | } 665 | -------------------------------------------------------------------------------- /kibana_scripts/ch04_mapping.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## A handy scripts file for hands-on exercises on Kibana 3 | ## Copy the whole contents of this file to Kibana's DevTools 4 | 5 | ## If you wish to follow the running commentary for these scripts, 6 | ## follow the Ch4 Mapping wiki page here: https://github.com/madhusudhankonda/elasticsearch-in-action/wiki/Ch-4.-Mapping 7 | ## 8 | ## Please let me know if you find any issues with this script 9 | ## 10 | ## Indexing a document for first time 11 | 12 | 13 | PUT movies/_doc/1 14 | { 15 | "title":"Godfather", 16 | "rating":4.9, 17 | "release_year":"1972/08/01" 18 | } 19 | 20 | ## Fixing the incorrect values 21 | ### Adding age field with text values to the student document 22 | 23 | PUT students_temp/_doc/1 24 | { 25 | "name":"John", 26 | "age":"12" 27 | } 28 | PUT students_temp/_doc/2 29 | { 30 | "name":"William", 31 | "age":"14" 32 | } 33 | 34 | # The sort query will result in error: 35 | GET students_temp/_search 36 | { 37 | "sort": [ 38 | { 39 | "age": { 40 | "order": "asc" 41 | } 42 | } 43 | ] 44 | } 45 | 46 | # The response indicates the operation is not allowed as the `age` has been defined as a text field. 47 | # To fix this, sort on `age.keyword` as the following query demonstrates: 48 | 49 | GET students_temp/_search 50 | { 51 | "sort": [ 52 | { 53 | "age.keyword": { 54 | "order": "asc" 55 | } 56 | } 57 | ] 58 | } 59 | 60 | ## Update existing schema 61 | 62 | PUT employees/_mapping 63 | { 64 | "properties":{ 65 | "joining_date":{ 66 | "type":"date", 67 | "format":"dd-MM-yyyy" 68 | }, 69 | "phone_number":{ 70 | "type":"keyword" 71 | } 72 | } 73 | } 74 | 75 | # Create an empty index first 76 | PUT departments 77 | 78 | ## Updating an empty index 79 | PUT departments/_mapping 80 | { 81 | "properties":{ 82 | "name":{ 83 | "type":"text" 84 | } 85 | } 86 | } 87 | ## Reindexing 88 | POST _reindex 89 | { 90 | "source": {"index": "orders"}, 91 | "dest": {"index": "orders_new"} 92 | } 93 | ## Type coercion 94 | PUT cars/_doc/1 95 | { 96 | "make":"BMW", 97 | "model":"X3", 98 | "age":"23" 99 | } 100 | ### Using standard (default) analyser 101 | POST _analyze 102 | { 103 | "text": "The movie was sick!!! Hilarious :) :) and WITTY ;) a KiLLer 👍" 104 | } 105 | # The response is:`The movie was sick Hilarious and WITTY a KiLLer 👍` 106 | ### Using English analyser 107 | #We can change the analyser to any of the out-of-box analysers by setting a anlyzer field. We demonstrate this below for testing a text with an English analyzer: 108 | POST _analyze 109 | { 110 | "text": "The movie was sick!!! Hilarious :) :) and WITTY ;) a KiLLer 👍", 111 | "analyzer": "english" 112 | } 113 | 114 | #The response from the English analyser is: `movi,sick,hilari, witti, killer, 👍` 115 | #The stemmed words like `movi`, `hilari`, `witti` are not real words, but the incorrect spellings don’t matter as long as all the derived forms can match the stemmed words. 116 | ## The token_count type 117 | PUT tech_books 118 | { 119 | "mappings": { 120 | "properties": { 121 | "title": { 122 | "type": "token_count", 123 | "analyzer": "standard" 124 | } 125 | } 126 | } 127 | } 128 | 129 | #Insert some adhoc docs: 130 | 131 | PUT tech_books/_doc/1 132 | { 133 | "title":"Elasticsearch in Action" 134 | } 135 | 136 | PUT tech_books/_doc/2 137 | { 138 | "title":"Elasticsearch for Java Developers" 139 | } 140 | 141 | PUT tech_books/_doc/3 142 | { 143 | "title":"Elastic Stack in Action" 144 | } 145 | 146 | #Finally, let's put the token_count to use: 147 | 148 | GET tech_books/_search 149 | { 150 | "query": { 151 | "range": { 152 | "title": { 153 | "gt": 3, 154 | "lte": 5 155 | } 156 | } 157 | } 158 | } 159 | 160 | ## Combining types 161 | ## We can combine the title field as a text type as well as a token_type: 162 | 163 | PUT tech_books 164 | { 165 | "mappings": { 166 | "properties": { 167 | "title": { 168 | "type": "text", 169 | "fields": { 170 | "word_count": { 171 | "type": "token_count", 172 | "analyzer": "standard" 173 | } 174 | } 175 | } 176 | } 177 | } 178 | } 179 | 180 | # Now we can issue a query to fetch titles with word count more than 4: 181 | 182 | GET tech_books/_search 183 | { 184 | "query": { 185 | "term": { 186 | "title.word_count": { 187 | "value": 4 188 | } 189 | } 190 | } 191 | } 192 | 193 | ### The `keyword` type 194 | # Create an index with `email` as a keyword type: 195 | 196 | PUT faculty 197 | { 198 | "mappings": { 199 | "properties": { 200 | "email": { 201 | "type": "keyword" 202 | } 203 | } 204 | } 205 | } 206 | 207 | ### The `constant_keyword` data type 208 | # Census index with country declared as `constant_keyword` and UK as value 209 | 210 | PUT census 211 | { 212 | "mappings": { 213 | "properties": { 214 | "country":{ 215 | "type": "constant_keyword", 216 | "value":"United Kingdom" 217 | } 218 | } 219 | } 220 | } 221 | 222 | #Index a document for John Doe, with just his name (no `country` field): 223 | 224 | PUT census/_doc/1 225 | { 226 | "name":"John Doe" 227 | } 228 | 229 | # When we search for all residents of the UK (though the document hasn’t got that field during indexing), we receive the positive result - returning John’s document: 230 | 231 | GET census/_search 232 | { 233 | "query": { 234 | "term": { 235 | "country": { 236 | "value": "United Kingdom" 237 | } 238 | } 239 | } 240 | } 241 | 242 | #The `constant_keyword` field will have exactly the same value for every document in that index. 243 | 244 | ### Wildcard type 245 | #The `wildcard` query to fetch documents matching to a value set as wildcard: 246 | 247 | GET errors/_search 248 | { 249 | "query": { 250 | "wildcard": { 251 | "description": { 252 | "value": "*obj*" 253 | } 254 | } 255 | } 256 | } 257 | 258 | ## Date type 259 | #Creating an index with a date type 260 | 261 | PUT flights 262 | { 263 | "mappings": { 264 | "properties": { 265 | "departure_date_time":{ 266 | "type": "date" 267 | } 268 | } 269 | } 270 | } 271 | 272 | #We can customize the departure date in multiple formats too: 273 | 274 | #"departure_date_time":{ 275 | # "type": "date", 276 | # "format": "dd-MM-yyyy||dd-MM-yy" 277 | #} 278 | 279 | #Issue a range query fetching documents between two date/time slots: 280 | 281 | #"range": { 282 | # "departure_date_time": { 283 | # "gte": "2021-08-06T05:00:00", 284 | # "lte": "2021-08-06T05:30:00" 285 | # } 286 | #} 287 | 288 | ## Boolean type 289 | 290 | PUT blockbusters 291 | { 292 | "mappings": { 293 | "properties": { 294 | "blockbuster":{ 295 | "type": "boolean" 296 | } 297 | } 298 | } 299 | } 300 | 301 | #Index couple of movies: Avatar as a blockbuster and Mulan(2020) as a flop, shown in the code snippet below: 302 | 303 | PUT blockbusters/_doc/2 304 | { 305 | "title":"Avatar", 306 | "blockbuster":true 307 | } 308 | 309 | PUT blockbusters/_doc/2 310 | { 311 | "title":"Mulan", 312 | "blockbuster":"false" 313 | } 314 | 315 | #The following query will fetch the Avatar as the blockbuster: 316 | 317 | GET blockbusters/_search 318 | { 319 | "query": { 320 | "term": { 321 | "blockbuster": { 322 | "value": "true" 323 | } 324 | } 325 | } 326 | } 327 | 328 | #Note: you can also provide an empty string for a false value: "blockbuster":"" 329 | ## The Range data types 330 | 331 | 332 | ### The `date_range` type 333 | #Index a `trainings` index with `date_range` type field: 334 | 335 | PUT trainings 336 | { 337 | "mappings": { 338 | "properties": { 339 | "name":{ 340 | "type": "text" 341 | }, 342 | "training_dates":{ 343 | "type": "date_range" 344 | } 345 | } 346 | } 347 | } 348 | 349 | #Let’s go ahead and index a few documents with Venkat’s training courses and dates. 350 | 351 | PUT trainings/_doc/1 352 | { 353 | "name":"Functional Programming in Java", 354 | "training_dates":{ 355 | "gte":"2021-08-07", 356 | "lte":"2021-08-10" 357 | } 358 | } 359 | PUT trainings/_doc/2 360 | { 361 | "name":"Programming Kotlin", 362 | "training_dates":{ 363 | "gte":"2021-08-09", 364 | "lte":"2021-08-12" 365 | } 366 | } 367 | 368 | PUT trainings/_doc/3 369 | { 370 | "name":"Reactive Programming", 371 | "training_dates":{ 372 | "gte":"2021-08-17", 373 | "lte":"2021-08-20" 374 | } 375 | } 376 | 377 | #The `data_range` type field expects two values: an upper bound and a lower bound. These are usually represented by abbreviations like gte (greater than or equal to), lt (less than), and so on. 378 | 379 | #Issue a search request to find out Venkat’s courses between two dates: 380 | 381 | GET trainings/_search 382 | { 383 | "query": { 384 | "range": { 385 | "training_dates": { 386 | "gt": "2021-08-10", 387 | "lt": "2021-08-12" 388 | } 389 | } 390 | } 391 | } 392 | 393 | #As a response to the query, we see Venkat is delivering _Programming Kotlin_ between these two dates (the second document matches for these dates). The data_range made it easy to search among a range of data. 394 | ## IP Address data type 395 | # Develop an index with a field of `ip` data type: 396 | 397 | PUT networks 398 | { 399 | "mappings": { 400 | "properties": { 401 | "router_ip":{ "type": "ip" } 402 | } 403 | } 404 | } 405 | 406 | #Indexing the document is then straight forward: 407 | 408 | PUT networks/_doc/1 409 | { 410 | "router_ip":"35.177.57.111" 411 | } 412 | 413 | #Issue the following query searches to data in the `networks` index to get the matching IP address: 414 | 415 | GET networks/_search 416 | { 417 | "query":{ 418 | "term": { 419 | "router_ip": { "value": "35.177.0.0/16" } 420 | } 421 | } 422 | } 423 | 424 | # Advanced data types 425 | ## Geo data type 426 | #Mapping schema for restaurants with address declared as `geo_point` type: 427 | 428 | PUT restaurants 429 | { 430 | "mappings": { 431 | "properties": { 432 | "name":{ 433 | "type": "text" 434 | }, 435 | "address":{ 436 | "type": "geo_point" 437 | } 438 | } 439 | } 440 | } 441 | 442 | #Indexing a restaurant with an address represented by longitude and latitude 443 | 444 | PUT restaurants/_doc/1 445 | { 446 | "name":"Sticky Fingers", 447 | "address":{ 448 | "lon":"0.1278", 449 | "lat":"51.5074" 450 | } 451 | } 452 | 453 | #To search for a restaurant in a bounded area, we write the `geo_bounding_box` filter providing the address in the form of a rectangle with `top_let` and `bottom_right` coordinates given as latitude and longitude: 454 | 455 | GET restaurants/_search 456 | { 457 | "query": { 458 | "geo_bounding_box":{ 459 | "address":{ 460 | "top_left":{ 461 | "lon":"0", 462 | "lat":"52" 463 | }, 464 | "bottom_right":{ 465 | "lon":"1", 466 | "lat":"50" 467 | } 468 | } 469 | } 470 | } 471 | } 472 | 473 | ## Object data type 474 | #Define the schema definitions for `emails` model with object data types: 475 | 476 | 477 | PUT emails 478 | { 479 | "mappings": { 480 | "properties": { 481 | "to":{ 482 | "type": "text" 483 | }, 484 | "subject":{ 485 | "type": "text" 486 | }, 487 | "attachments":{ 488 | "properties": { 489 | "filename":{ 490 | "type":"text" 491 | }, 492 | "filetype":{ 493 | "type":"text" 494 | } 495 | } 496 | } 497 | } 498 | } 499 | } 500 | 501 | #Indexing an email document with all the relevant fields 502 | 503 | PUT emails/_doc/1 504 | { 505 | "to:":"johndoe@johndoe.com", 506 | "subject":"Testing Object Type", 507 | "attachments":{ 508 | "filename":"file1.txt", 509 | "filetype":"confidential" 510 | } 511 | } 512 | 513 | #Searching for emails with a said attachment file: 514 | 515 | GET emails/_search 516 | { 517 | "query": { 518 | "match": { 519 | "attachments.filename": "file1.txt" 520 | } 521 | } 522 | } 523 | 524 | ### Limitations of an `object` type 525 | #Index a document with multiple attachments: 526 | 527 | PUT emails/_doc/2 528 | { 529 | "to:":"mrs.doe@johndoe.com", 530 | "subject":"Multi attachments test", 531 | "attachments":[{ 532 | "filename":"file2.txt", 533 | "filetype":"confidential" 534 | },{ 535 | "filename":"file3.txt", 536 | "filetype":"private" 537 | }] 538 | } 539 | 540 | #Advanced bool query with term queries for a match with a filename and filetype 541 | 542 | GET myemails/_search 543 | { 544 | "query": { 545 | "bool": { 546 | "must": [ 547 | {"term": { "attachments.filename.keyword": "file2.txt"}}, 548 | {"term": { "attachments.filetype.keyword": "private" }} 549 | ] 550 | } 551 | } 552 | } 553 | 554 | ## Nested data type 555 | #Mapping schema definition for nested type: 556 | 557 | PUT emails_nested 558 | { 559 | "mappings": { 560 | "properties": { 561 | "attachments": { 562 | "type": "nested", 563 | "properties": { 564 | "filename": { 565 | "type": "keyword" 566 | }, 567 | "filetype": { 568 | "type": "text" 569 | } 570 | } 571 | } 572 | } 573 | } 574 | } 575 | 576 | #Indexing a sample document into an `emails_nested` with nested property: 577 | 578 | PUT emails_nested/_doc/1 579 | { 580 | "attachments" : [ 581 | { 582 | "filename" : "file1.txt", 583 | "filetype" : "confidential" 584 | }, 585 | { 586 | "filename" : "file2.txt", 587 | "filetype" : "private" 588 | } 589 | ] 590 | } 591 | 592 | # Fetching the documents that match `file1.txt` with `private` as the classification: 593 | GET emails_nested/_search 594 | { 595 | "query": { 596 | "nested": { 597 | "path": "attachments", 598 | "query": { 599 | "bool": { 600 | "must": [ 601 | { "match": { "attachments.filename": "file1.txt" }}, 602 | { "match": { "attachments.filetype": "private" }} 603 | ] 604 | } 605 | } 606 | } 607 | } 608 | } 609 | 610 | ## Flattened data type 611 | # Create a mapping with flattened data type: 612 | 613 | PUT consultations 614 | { 615 | "mappings": { 616 | "properties": { 617 | "patient_name":{ 618 | "type": "text" 619 | }, 620 | "doctor_notes":{ 621 | "type": "flattened" 622 | } 623 | } 624 | } 625 | } 626 | 627 | # Indexing the consultation document with doctor’s notes: 628 | 629 | PUT consultations/_doc/1 630 | { 631 | "patient_name":"John Doe", 632 | "doctor_notes":{ 633 | "temperature":103, 634 | "symptoms":["chills","fever","headache"], 635 | "history":"none", 636 | "medication":["Antibiotics","Paracetamol"] 637 | } 638 | } 639 | 640 | # Searching through the flattened data type field 641 | 642 | GET consultations/_search 643 | { 644 | "query": { 645 | "match": { 646 | "doctor_notes": "Paracetamol" 647 | } 648 | } 649 | } 650 | 651 | # An advanced query on a flattened data type: 652 | 653 | GET consultations/_search 654 | { 655 | "query": { 656 | "bool": { 657 | "must": [{"match": {"doctor_notes": "headache"}}, 658 | {"match": {"doctor_notes": "Antibiotics"}}], 659 | "must_not": [{"term": {"doctor_notes": {"value": "diabetics"}}}] 660 | } 661 | } 662 | } 663 | 664 | ## Join data type 665 | # Mapping of the doctors schema definition 666 | 667 | PUT doctors 668 | { 669 | "mappings": { 670 | "properties": { 671 | "relationship":{ 672 | "type": "join", 673 | "relations":{ 674 | "doctor":"patient" 675 | } 676 | } 677 | } 678 | } 679 | } 680 | 681 | # Indexing a doctor document - note the relationship attribute: 682 | 683 | PUT doctors/_doc/1 684 | { 685 | "name":"Dr Mary Montgomery", 686 | "relationship":{ 687 | "name":"doctor" 688 | } 689 | } 690 | 691 | # Creating two patients for our doctor: 692 | 693 | PUT doctors/_doc/2?routing=mary 694 | { 695 | "name":"John Doe", 696 | "relationship":{ 697 | "name":"patient", 698 | "parent":1 699 | } 700 | } 701 | 702 | PUT doctors/_doc/3?routing=mary 703 | { 704 | "name":"Mrs Doe", 705 | "relationship":{ 706 | "name":"patient", 707 | "parent":1 708 | } 709 | } 710 | 711 | #Fetching the patients of Dr Montgomery 712 | 713 | GET doctors/_search 714 | { 715 | "query": { 716 | "parent_id":{ 717 | "type":"patient", 718 | "id":1 719 | } 720 | } 721 | } 722 | 723 | #Mapping schema for technical books with the title as search_as_you_type type 724 | 725 | PUT tech_books 726 | { 727 | "mappings": { 728 | "properties": { 729 | "title": { 730 | "type": "search_as_you_type" 731 | } 732 | } 733 | } 734 | } 735 | 736 | #Indexing a few books: 737 | 738 | PUT tech_books4/_doc/1 739 | { 740 | "title":"Elasticsearch in Action" 741 | } 742 | 743 | PUT tech_books4/_doc/2 744 | { 745 | "title":"Elasticsearch for Java Developers" 746 | } 747 | 748 | PUT tech_books4/_doc/3 749 | { 750 | "title":"Elastic Stack in Action" 751 | } 752 | 753 | # Searching in a search_as_you_type field and its subfields 754 | 755 | GET tech_books4/_search 756 | { 757 | "query": { 758 | "multi_match": { 759 | "query": "in", 760 | "type": "bool_prefix", 761 | "fields": ["title","title._2gram","title._3gram"] 762 | } 763 | } 764 | } 765 | 766 | 767 | # _index_prefix produces edge n-grams - [e, el, ela, elas, elast, elasti, elastic] 768 | GET tech_books4/_analyze 769 | { 770 | "field": "title._index_prefix", 771 | "text": ["Elastic"] 772 | } 773 | 774 | # 2gram produces two tokens - [elaticsearch, in],[in, action] 775 | GET tech_books4/_analyze 776 | { 777 | "field": "title._2gram", 778 | "text": ["Elasticsearch in Action"] 779 | } 780 | 781 | # 3gram produces three tokens - [elaticsearch, for, java],[for, java, developers] 782 | GET tech_books4/_analyze 783 | { 784 | "field": "title._3gram", 785 | "text": ["Elasticsearch for Java Developers"] 786 | } 787 | 788 | 789 | # This query should return the Elasticsearch in Action and Elastic Stack in Action books. 790 | ## Multi types 791 | #Schema definition with multi-typed field: 792 | 793 | PUT emails 794 | { 795 | "mappings": { 796 | "properties": { 797 | "subject":{ 798 | "type": "text", 799 | "fields": { 800 | "kw":{ "type":"keyword" }, 801 | "comp":{ "type":"completion" } 802 | } 803 | } 804 | } 805 | } 806 | } 807 | -------------------------------------------------------------------------------- /kibana_scripts/ch05_working_with_documents.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## A handy scripts file for hands-on exercises on Kibana 3 | ## Copy the whole contents of this file to Kibana's DevTools 4 | ### Indexing a movie document with an identifier: 5 | 6 | PUT movies/_doc/1 7 | { 8 | "title":"The Godfather", 9 | "synopsis":"The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son" 10 | } 11 | 12 | ## Posting a movie review without an ID 13 | POST movies_reviews/_doc 14 | { 15 | "movie":"The Godfather", 16 | "user":"Peter Piper", 17 | "rating":4.5, 18 | "remarks":"The movie started with a ..." 19 | } 20 | 21 | # Movie with an ID 22 | POST movies/_doc/1 23 | { 24 | "movie":"The Godfather", 25 | } 26 | 27 | #A Not a movie but a tweet - overriding existing movie 28 | PUT movies/_doc/1 29 | { 30 | "tweet":"Elasticsearch in Action 2e is here!" 31 | } 32 | 33 | # Using _create endpoint to avoid overriding. 34 | # First create a movie with ID 100 35 | PUT movies/_create/100 36 | { 37 | "title":"Mission: Impossible", 38 | "director":"Brian De Palma" 39 | } 40 | 41 | # Now, index a tweet in place of an existing movie - this op should fail 42 | PUT movies/_create/100 43 | { 44 | "tweet":"A movie with popcorn is so cool!" 45 | } 46 | 47 | # Stop auto creation of indices 48 | PUT _cluster/settings 49 | { 50 | "persistent": { 51 | "action.auto_create_index": "false" 52 | } 53 | } 54 | 55 | # Using multi-get (_mget) API to get multiple docs 56 | GET movies/_mget 57 | { 58 | "ids" : ["1", "12", "19", "34"] 59 | } 60 | 61 | # Check if doc exists 62 | HEAD movies/_doc/1 63 | 64 | # Fetching docs from multiple indices using _mget endpoint 65 | GET _mget 66 | { 67 | "docs":[ 68 | { 69 | "_index":"classic_movies", 70 | "_id":11 71 | }, 72 | { 73 | "_index":"international_movies", 74 | "_id":22 75 | }, 76 | { 77 | "_index":"top100_movies", 78 | "_id":33 79 | } 80 | ] 81 | } 82 | 83 | # Use ids query to fetch multiple documents 84 | GET classic_movies/_search 85 | { 86 | "query": { 87 | "ids": { 88 | "values": [1,2,3,4] 89 | } 90 | } 91 | } 92 | 93 | # Fetching multiple docs from multiple indices 94 | GET classic_movies,international_movies/_search 95 | { 96 | # body 97 | } 98 | 99 | # Updating documents 100 | 101 | ### Adding new fields 102 | POST movies/_update/1 103 | { 104 | "doc": { 105 | "actors":["Marlon Brando","Al Pacino","James Caan"], 106 | "director":"Francis Ford Coppola" 107 | } 108 | } 109 | 110 | ### Modify an existing document 111 | POST movies/_update/1 112 | { 113 | "doc": { 114 | "title":"The Godfather (Original)" 115 | } 116 | } 117 | 118 | GET movies/_doc/1 119 | 120 | ### Adding a new value to the actors array 121 | POST movies/_update/1 122 | { 123 | "doc": { 124 | "actors":["Marlon Brando","Al Pacino","James Caan", "Robert Duvall"] 125 | } 126 | } 127 | 128 | ## Scripted updates 129 | ### Adding additional actor via the script 130 | POST movies/_update/1 131 | { 132 | "script": { 133 | "source": "ctx._source.actors.add('Diane Keaton')" 134 | } 135 | } 136 | 137 | GET movies/_doc/1 138 | 139 | ## Removing an actor using the script 140 | POST movies/_update/1 141 | { 142 | "script": { 143 | "source": "ctx._source.actors.remove(ctx._source.actors.indexOf('Diane Keaton'))" 144 | } 145 | } 146 | 147 | ### Adding a new field 148 | POST movies/_update/1 149 | { 150 | "script": { 151 | "source": "ctx._source.imdb_user_rating = 9.2" 152 | } 153 | } 154 | 155 | ### Removing a field 156 | POST movies/_update/1 157 | { 158 | "script": { 159 | "source": "ctx._source.remove('metacritic_rating')" 160 | } 161 | } 162 | 163 | ### Adding multiple fields 164 | POST movies/_update/1 165 | { 166 | "script": { 167 | "source": """ 168 | ctx._source.runtime_in_minutes = 175; 169 | ctx._source.metacritic_rating= 100; 170 | ctx._source.tomatometer = 97; 171 | ctx._source.boxoffice_gross_in_millions = 134.8; 172 | """ 173 | } 174 | } 175 | 176 | ### Conditional updates 177 | POST movies/_update/1 178 | { 179 | "script": { 180 | "source": """ 181 | if(ctx._source.boxoffice_gross_in_millions > 125) 182 | {ctx._source.blockbuster = true} 183 | else 184 | {ctx._source.blockbuster = false} 185 | """ 186 | } 187 | } 188 | 189 | ### Retrieve the document 190 | GET movies/_doc/1 191 | 192 | ### Dynamically passing a parameter to the script 193 | POST movies/_update/1 194 | { 195 | "script": { 196 | "source": """ 197 | if(ctx._source.boxoffice_gross_in_millions > params.gross_earnings_threshold) 198 | {ctx._source.blockbuster = true} 199 | else 200 | {ctx._source.blockbuster = false} 201 | """, 202 | "params": { 203 | "gross_earnings_threshold":150 204 | } 205 | } 206 | } 207 | 208 | ### Upsert 209 | POST movies/_update/5 210 | { 211 | "script": { 212 | "source": "ctx._source.gross_earnings = '357.1m'" 213 | }, 214 | "upsert": { 215 | "title":"Top Gun", 216 | "gross_earnings":"357.5m" 217 | } 218 | } 219 | 220 | ## Updating a non-existing field will throw an error 221 | POST movies/_update/11 222 | { 223 | "doc": { 224 | "runtime_in_minutes":110 225 | } 226 | } 227 | 228 | ## Updating a non-existing field that throws an error fixed with doc_as_upsert flag 229 | POST movies/_update/11 230 | { 231 | "doc": { 232 | "runtime_in_minutes":110 233 | }, 234 | "doc_as_upsert":true 235 | } 236 | 237 | ### Updating the document using a query method 238 | POST movies/_update_by_query 239 | { 240 | "query": { 241 | "match": { 242 | "actors": "Al Pacino" 243 | } 244 | }, 245 | 246 | "script": { 247 | "source": """ 248 | ctx._source.actors.add('Oscar Winner Al Pacino'); 249 | ctx._source.actors.remove(ctx._source.actors.indexOf('Al Pacino')) 250 | """, 251 | "lang": "painless" 252 | } 253 | } 254 | 255 | ## Deleting documents 256 | 257 | ### Deleting a document given an ID 258 | DELETE movies/_doc/1 259 | 260 | ## Delete by query 261 | ### Add three sample documents 262 | PUT movies/_doc/101 263 | { 264 | "title":"Jaws", 265 | "director":"Steven Spielberg", 266 | "gross_earnings_in_millions":355 267 | } 268 | 269 | PUT movies/_doc/102 270 | { 271 | "title":"Jaws II", 272 | "director":"Steven Spielberg", 273 | "gross_earnings_in_millions":375 274 | } 275 | 276 | PUT movies/_doc/103 277 | { 278 | "title":"Jaws III", 279 | "director":"Steven Spielberg", 280 | "gross_earnings_in_millions":300 281 | } 282 | 283 | # Delete the movies by a range query 284 | POST movies/_delete_by_query 285 | { 286 | "query": { 287 | "range": { 288 | "gross_earnings_in_millions": { 289 | "gt": 350, 290 | "lt": 400 291 | } 292 | } 293 | } 294 | } 295 | 296 | #Not found 297 | GET movies/_doc/101 298 | 299 | #Not found 300 | GET movies/_doc/102 301 | 302 | #Found the movie 303 | GET movies/_doc/103 304 | 305 | 306 | ## Complex delete query 307 | POST movies/_delete_by_query 308 | { 309 | "query": { 310 | "bool": { 311 | "must": [ 312 | { 313 | "match": { 314 | "director": "Steven Spielberg" 315 | } 316 | } 317 | ], 318 | "must_not": [ 319 | { 320 | "range": { 321 | "imdb_rating": { 322 | "gte": 9, 323 | "lte": 9.5 324 | } 325 | } 326 | } 327 | ], 328 | "filter": [ 329 | { 330 | "range": { 331 | "gross_earnings_in_millions": { 332 | "lt": 100 333 | } 334 | } 335 | } 336 | ] 337 | } 338 | } 339 | } 340 | 341 | ## Bulk indexing 342 | 343 | POST _bulk 344 | {"index":{"_index":"movies","_id":"100"}} 345 | {"title": "Mission Impossible","release_date": "1996-07-05"} 346 | 347 | 348 | POST movies/_bulk 349 | {"index":{"_id":"100"}} 350 | {"title": "Mission Impossible","release_date": "1996-07-05"} 351 | 352 | ## Tom Cruise's movies 353 | POST movies/_bulk 354 | {"index":{}} 355 | {"title": "Mission Impossible","release_date": "1996-07-05"} 356 | {"index":{}} 357 | {"title": "Mission Impossible II","release_date": "2000-05-24"} 358 | {"index":{}} 359 | {"title": "Mission Impossible III","release_date": "2006-05-03"} 360 | {"index":{}} 361 | {"title": "Mission Impossible - Ghost Protocol","release_date": "2011-12-26"} 362 | 363 | # Create Rush Hour Movie 364 | POST _bulk 365 | {"index":{"_index":"movies","_id":"200"}} 366 | {"doc": {"director":"Brett Ratner"}} 367 | 368 | # Update the Rush Hour movie 369 | POST _bulk 370 | {"update":{"_index":"movies","_id":"200"}} 371 | {"doc": {"director":"Brett Ratner", "actors":["Jackie Chan","Chris Tucker"]}} 372 | 373 | 374 | 375 | ## Multiple entities 376 | 377 | POST _bulk 378 | {"index":{"_index":"books"}} 379 | {"title": "Elasticsearch in Action"} 380 | {"create":{"_index":"flights", "_id":"101"}} 381 | {"title": "London to Bucharest"} 382 | {"index":{"_index":"pets"}} 383 | {"name": "Milly","age_months": 18} 384 | {"delete":{"_index":"movies", "_id":"101"}} 385 | { "update" : {"_index":"movies", "_id":"1"} } 386 | { "doc" : {"title" : "The Godfather (Original)"} } 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | -------------------------------------------------------------------------------- /kibana_scripts/ch06_indexing_operations.txt: -------------------------------------------------------------------------------- 1 | ## 2 | ## A handy scripts file for hands-on exercises on Kibana 3 | ## Copy the whole contents of this file to Kibana's DevTools 4 | 5 | ## If you wish to follow the running commentary for these scripts, 6 | ## follow the Ch6 Text Analysis wiki page here: https://github.com/madhusudhankonda/elasticsearch-in-action/wiki/Ch-6.-Indexing Operations 7 | ## 8 | ## Please let me know if you find any issues with this script 9 | ## 10 | 11 | ## Indexing Documents 12 | 13 | ### Indexing a movie document with an identifier: 14 | # First document containing car data 15 | PUT cars/_doc/1 16 | { 17 | "make":"Maserati", 18 | "model":"GranTurismo Sport", 19 | "speed_mph":186 20 | } 21 | 22 | # Disabling automatic creation of indices 23 | # Don't execute it for now as it will hamper your progress 24 | # executing the rest of the script 25 | # PUT _cluster/settings 26 | # { 27 | # "persistent": { 28 | # "action.auto_create_index":false 29 | # } 30 | # } 31 | 32 | # Index with sample mapping 33 | PUT cars_index_with_sample_mapping 34 | { 35 | "mappings": { 36 | "properties": { 37 | "make":{ 38 | "type": "text" 39 | } 40 | } 41 | } 42 | } 43 | 44 | #Index with custom settings 45 | PUT cars_index_with_sample_settings 46 | { 47 | "settings": { 48 | "number_of_replicas": 3, 49 | "codec": "best_compression" 50 | } 51 | } 52 | 53 | # Creating an index with an alias 54 | PUT cars_index_with_sample_alias 55 | { 56 | "aliases": { 57 | "alias_for_cars_index_with_sample_alias": {} 58 | } 59 | } 60 | 61 | # Creating an index with custom settings 62 | PUT cars_with_custom_settings 63 | { 64 | "settings":{ 65 | "number_of_shards":3, 66 | "number_of_replicas":5, 67 | "codec": "best_compression", 68 | "max_script_fields":128, 69 | "refresh_interval": "60s" 70 | } 71 | } 72 | 73 | # Updating dynamic property on an index 74 | PUT cars_with_custom_settings/_settings 75 | { 76 | "settings": { 77 | "number_of_replicas": 2 78 | } 79 | } 80 | 81 | 82 | # Fetching the settings of an index 83 | GET cars_with_custom_settings/_settings 84 | 85 | # Pre-requisite to create three car indices for the next query to pass 86 | PUT cars1 87 | PUT cars2 88 | PUT cars3 89 | 90 | # Fetching the settings of multiple indices in one go 91 | GET cars1,cars2,cars3/_settings 92 | 93 | # Fetches the settings for the index identified with a wildcard (*) 94 | GET cars*/_settings 95 | 96 | # Fetching a single attribute 97 | GET cars_with_custom_settings/_settings/index.number_of_shards 98 | 99 | #Creating an index with field mappings for a car document 100 | PUT cars_with_mappings 101 | { 102 | "mappings": { 103 | "properties": { 104 | "make":{ 105 | "type": "text" 106 | }, 107 | "model":{ 108 | "type": "text" 109 | }, 110 | "registration_year":{ 111 | "type": "date", 112 | "format": "dd-MM-yyyy" 113 | } 114 | } 115 | } 116 | } 117 | 118 | #Creating an index with both settings and mappings 119 | PUT cars_with_settings_and_mappings 120 | { 121 | "settings": { 122 | "number_of_replicas": 3 123 | }, 124 | "mappings": { 125 | "properties": { 126 | "make":{ 127 | "type": "text" 128 | } 129 | } 130 | } 131 | } 132 | 133 | # Creating an alias using an aliases object 134 | PUT cars_for_aliases 135 | { 136 | "aliases": { 137 | "my_new_cars_alias": {} 138 | } 139 | } 140 | 141 | # Creating an alias using an _alias endpoint 142 | PUT cars_for_aliases/_alias/my_cars_alias 143 | 144 | # Creating an alias using an _alias endpoint 145 | PUT cars_for_aliases/_alias/all_cars_alias 146 | 147 | # Creating a single alias pointing to multiple indices 148 | PUT cars1,cars2,cars3/_alias/multi_cars_alias 149 | 150 | 151 | # Creating an alias with a wildcard 152 | PUT cars*/_alias/wildcard_cars_alias 153 | 154 | #Fetching aliases, settings, and mappings for an index 155 | GET cars 156 | 157 | # Getting an alias on a single index 158 | GET my_cars_alias/_alias 159 | 160 | 161 | # Fetching aliases associated with multiple indices 162 | GET all_cars_alias,my_cars_alias/_alias 163 | 164 | #Prerequisite in getting the next query executed successfully 165 | PUT vintage_cars 166 | PUT vintage_cars_new 167 | 168 | # Performing multiple aliasing operations 169 | POST _aliases 170 | { 171 | "actions": [ 172 | { 173 | "remove": { 174 | "index": "vintage_cars", 175 | "alias": "vintage_cars_alias" 176 | } 177 | }, 178 | { 179 | "add": { 180 | "index": "vintage_cars_new", 181 | "alias": "vintage_cars_alias" 182 | } 183 | } 184 | ] 185 | } 186 | 187 | # Prerequiste for the next query 188 | PUT power_cars 189 | PUT rare_cars 190 | PUT luxury_cars 191 | 192 | # Creating an alias pointing to multiple indice 193 | POST _aliases 194 | { 195 | "actions": [ 196 | { 197 | "add": { 198 | "indices": ["vintage_cars","power_cars","rare_cars","luxury_cars"], 199 | "alias": "high_end_cars_alais" 200 | } 201 | } 202 | ] 203 | } 204 | 205 | 206 | # Getting index configurations for multiple indices 207 | GET cars1,cars2,cars3 208 | 209 | # Getting multiple index configurations with a wildcard 210 | GET ca* 211 | 212 | # Fetching configurations for specific indices 213 | GET mov*,stu* 214 | 215 | 216 | 217 | # Getting individual configurations for an index 218 | GET cars/_settings 219 | GET cars/_mapping 220 | GET cars/_alias 221 | 222 | #Prerequisite for the next query 223 | PUT cars/_alias/cars_alias 224 | 225 | #Deleting an alias explicitly 226 | DELETE cars/_alias/cars_alias 227 | 228 | # Closing the cars index indefinitely 229 | POST cars/_close?wait_for_active_shards=index-setting 230 | 231 | # Closing multiple indices 232 | POST cars1,*mov*,students*/_close?wait_for_active_shards=index-setting 233 | 234 | #Halt all the live operations using _all or *: 235 | # I am commenting this out - uncomment only when you know what you are doing. 236 | # Refer to Book for more informtion 237 | 238 | # POST */_close?wait_for_active_shards=index-setting 239 | 240 | # Disabling the action to close all indices 241 | # Caution: Make sure you understand the implication of this command. Refer to book notes 242 | PUT _cluster/settings 243 | { 244 | "persistent": { 245 | "action.destructive_requires_name":true 246 | } 247 | } 248 | 249 | # Disabling the closing indices feature 250 | # Caution: Make sure you understand the implication of this command. Refer to book notes 251 | PUT _cluster/settings 252 | { 253 | "persistent": { 254 | "cluster.indices.close.enable":false 255 | } 256 | } 257 | 258 | 259 | 260 | # Putting the index back into operation 261 | POST cars/_open 262 | 263 | 264 | # Creating an index template 265 | POST _index_template/cars_template 266 | { 267 | "index_patterns": ["*cars*"], 268 | "priority": 1, 269 | "template": { 270 | "mappings": { 271 | "properties":{ 272 | "created_at":{ 273 | "type":"date" 274 | }, 275 | "created_by":{ 276 | "type":"text" 277 | } 278 | } 279 | } 280 | } 281 | } 282 | 283 | 284 | 285 | # the cars_template_mar21 overrides the cars_template_feb21 in the following code snippet (though the names suggest the other way!): 286 | #POST _index_template/cars_template_mar21 287 | #{ 288 | # "index_patterns": ["*cars*"], 289 | # "priority": 20, 290 | # "template": { ... } 291 | #} 292 | 293 | #POST _index_template/cars_template_feb21 294 | #{ 295 | # "index_patterns": ["*cars*"], 296 | # "priority": 30, 297 | # "template": { ... } 298 | #} 299 | #A The lower priority index template 300 | #B Same matching template but with a higher priority 301 | 302 | 303 | # Developing a component template 304 | POST _component_template/dev_settings_component_template 305 | { 306 | "template":{ 307 | "settings":{ 308 | "number_of_shards":3, 309 | "number_of_replicas":3 310 | } 311 | } 312 | } 313 | 314 | 315 | # A component template with a mapping schema 316 | POST _component_template/dev_mapping_component_template 317 | { 318 | "template": { 319 | "mappings": { 320 | "properties": { 321 | "created_by": { 322 | "type": "text" 323 | }, 324 | "version": { 325 | "type": "float" 326 | } 327 | } 328 | } 329 | } 330 | } 331 | 332 | 333 | 334 | # Creating an index template composed of a component template 335 | POST _index_template/composed_cars_template 336 | { 337 | "index_patterns": ["*cars*"], 338 | "priority": 200, 339 | "composed_of": ["dev_settings_component_template", 340 | "dev_mapping_component_template"] 341 | } 342 | 343 | 344 | # Fetching the statistics of an index 345 | GET cars/_stats 346 | 347 | # Fetching the statistics for multiple indices 348 | GET cars*/_stats 349 | 350 | # Fetching the statistics for all indices in the cluster 351 | GET */_stats 352 | 353 | #The following snippet shows how to return the statistics in segments: 354 | GET cars/_stats/segments 355 | 356 | 357 | # Prerequisite for the next query 358 | PUT all_cars 359 | 360 | # Making sure the index is read-only 361 | PUT all_cars/_settings 362 | { 363 | "settings":{ 364 | "index.blocks.write":"true" 365 | } 366 | } 367 | 368 | #Splitting the all_cars index 369 | # Note the target index’s primary shard number must be a multiple of the number of primary shards of the source index. Refer to book for more details. 370 | 371 | POST all_cars/_split/all_cars_new 372 | { 373 | "settings": { 374 | "index.number_of_shards": 12 375 | } 376 | } 377 | 378 | # This query will throw an exception. That’s because we violated the second rule (see book notes): 379 | # "reason" : "the number of source shards [3] must be a factor of [14]" 380 | 381 | POST all_cars/_split/all_cars_new 382 | { 383 | "settings": { 384 | "index.number_of_shards": 14 385 | } 386 | } 387 | 388 | 389 | #Carrying out the prerequisites before shrinking the index 390 | PUT all_cars/_settings 391 | { 392 | "settings": { 393 | "index.blocks.write": true, 394 | "index.routing.allocation.require._name": "node1" 395 | } 396 | } 397 | 398 | 399 | 400 | # Shrinking the index 401 | PUT all_cars/_shrink/all_cars_new2 402 | { 403 | "settings":{ 404 | "index.blocks.write":null, 405 | "index.routing.allocation.require._name":null, 406 | "index.number_of_shards":1, 407 | "index.number_of_replicas":5 408 | } 409 | } 410 | 411 | #Prerequisite for the next query 412 | PUT cars_2021-000001 413 | 414 | # Creating an alias for an existing index 415 | POST _aliases 416 | { 417 | "actions": [ 418 | { 419 | "add": { 420 | "index": "cars_2021-000001", 421 | "alias": "latest_cars_a", 422 | "is_write_index": true 423 | } 424 | } 425 | ] 426 | } 427 | 428 | # Rolling over the index 429 | POST latest_cars_a/_rollover 430 | 431 | # The response from the above rollover call: 432 | #{ 433 | # "acknowledged" : true, 434 | # "shards_acknowledged" : true, 435 | # "old_index" : "latest_cars-000001", #A Old index name 436 | # "new_index" : "latest_cars-000002", #B New index name 437 | # "rolled_over" : true, 438 | # "dry_run" : false, 439 | # "conditions" : { } 440 | #} 441 | 442 | # Creating a policy with hot and delete policies 443 | PUT _ilm/policy/hot_delete_policy 444 | { 445 | "policy": { 446 | "phases": { 447 | "hot": { 448 | "min_age": "1d", 449 | "actions": { 450 | "set_priority": { 451 | "priority": 250 452 | } 453 | } 454 | }, 455 | "delete": { 456 | "actions": { 457 | "delete" : { } 458 | } 459 | } 460 | } 461 | } 462 | } 463 | 464 | # Creating an index with an index life cycle 465 | PUT hot_delete_policy_index 466 | { 467 | "settings": { 468 | "index.lifecycle.name":"hot_delete_policy" 469 | } 470 | } 471 | 472 | #Simple policy definition for hot phase 473 | PUT _ilm/policy/hot_simple_policy 474 | { 475 | "policy": { 476 | "phases": { 477 | "hot": { 478 | "min_age": "0ms", 479 | "actions": { 480 | "rollover": { 481 | "max_age": "1d", 482 | "max_docs": 10000, 483 | "max_size": "10gb" 484 | } 485 | } 486 | } 487 | } 488 | } 489 | } 490 | 491 | # Attaching a life-cycle policy to a template 492 | PUT _index_template/mysql_logs_template 493 | { 494 | "index_patterns": ["mysql-*"], 495 | "template":{ 496 | "settings":{ 497 | "index.lifecycle.name":"hot_simple_policy", 498 | "index.lifecycle.rollover_alias":"mysql-logs-alias" 499 | } 500 | } 501 | } 502 | 503 | # Setting the index as writable for the alias 504 | PUT mysql-index-000001 505 | { 506 | "aliases": { 507 | "mysql-logs-alias": { 508 | "is_write_index":true 509 | } 510 | } 511 | } 512 | 513 | # Creating an advanced life-cycle policy 514 | PUT _ilm/policy/hot_warm_delete_policy 515 | { 516 | "policy": { 517 | "phases": { 518 | "hot": { 519 | "min_age": "1d", 520 | "actions": { 521 | "rollover": { 522 | "max_size": "40gb", 523 | "max_age": "6d" 524 | }, 525 | "set_priority": { 526 | "priority": 50 527 | } 528 | } 529 | }, 530 | "warm": { 531 | "min_age": "7d", 532 | "actions": { 533 | "shrink": { 534 | "number_of_shards": 1 535 | } 536 | } 537 | }, 538 | "delete": { 539 | "min_age": "30d", 540 | "actions": { 541 | "delete": {} 542 | } 543 | } 544 | } 545 | } 546 | } 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | -------------------------------------------------------------------------------- /kibana_scripts/ch08_search_basics.txt: -------------------------------------------------------------------------------- 1 | ## Sample movie index 2 | 3 | # Create movies index 4 | PUT movies 5 | { 6 | "mappings": { 7 | "properties": { 8 | "title": { 9 | "type": "text", 10 | "fields": { 11 | "original": { 12 | "type": "keyword" 13 | } 14 | } 15 | }, 16 | "synopsis": { 17 | "type": "text" 18 | }, 19 | "actors": { 20 | "type": "text" 21 | }, 22 | "director": { 23 | "type": "text" 24 | }, 25 | "rating": { 26 | "type": "half_float" 27 | }, 28 | "release_date": { 29 | "type": "date", 30 | "format": "dd-MM-yyyy" 31 | }, 32 | "certificate": { 33 | "type": "keyword" 34 | }, 35 | "genre": { 36 | "type": "text" 37 | } 38 | } 39 | } 40 | } 41 | 42 | POST _bulk 43 | {"index":{"_index":"movies","_id":"1"}} 44 | {"title": "The Shawshank Redemption","synopsis": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.","actors": ["Tim Robbins", "Morgan Freeman", "Bob Gunton", "William Sadler"] ,"director":" Frank Darabont ","rating":"9.3","certificate":"R","genre": "Drama "} 45 | {"index":{"_index":"movies","_id":"2"}} 46 | {"title": "The Godfather","synopsis": "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.","actors": ["Marlon Brando", "Al Pacino", "James Caan", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":"9.2","certificate":"R","genre": ["Crime", "Drama"] } 47 | {"index":{"_index":"movies","_id":"3"}} 48 | {"title": "The Dark Knight","synopsis": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, Batman must accept one of the greatest psychological and physical tests of his ability to fight injustice.","actors": ["Christian Bale", "Heath Ledger", "Aaron Eckhart", "Michael Caine"] ,"director":" Christopher Nolan ","rating":"9.0","certificate":"PG-13","genre": ["Action", "Crime", "Drama"] } 49 | {"index":{"_index":"movies","_id":"4"}} 50 | {"title": "The Godfather: Part II","synopsis": "The early life and career of Vito Corleone in 1920s New York City is portrayed, while his son, Michael, expands and tightens his grip on the family crime syndicate.","actors": ["Al Pacino", "Robert De Niro", "Robert Duvall", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":"9.0","certificate":"R","genre": ["Crime", "Drama"] } 51 | {"index":{"_index":"movies","_id":"5"}} 52 | {"title": "12 Angry Men","synopsis": "A jury holdout attempts to prevent a miscarriage of justice by forcing his colleagues to reconsider the evidence.","actors": ["Henry Fonda", "Lee J. Cobb", "Martin Balsam", " John Fiedler"] ,"director":" Sidney Lumet ","rating":"9.0","certificate":"Approved","genre": ["Crime", "Drama"] } 53 | {"index":{"_index":"movies","_id":"6"}} 54 | {"title": "The Lord of the Rings: The Return of the King","synopsis": "Gandalf and Aragorn lead the World of Men against Saurons's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring.","actors": ["Elijah Wood", "Viggo Mortensen", "Ian McKellen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":"8.9","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] } 55 | {"index":{"_index":"movies","_id":"7"}} 56 | {"title": "Pulp Fiction","synopsis": "The lives of two mob hitmen, a boxer, a gangster and his wife, and a pair of diner bandits intertwine in four tales of violence and redemption.","actors": ["John Travolta", "Uma Thurman", "Samuel L. Jackson", "Bruce Willis"] ,"director":" Quentin Tarantino ","rating":"8.9","certificate":"R","genre": ["Crime", "Drama"] } 57 | {"index":{"_index":"movies","_id":"8"}} 58 | {"title": "Schindler's List","synopsis": "In German-occupied Poland during World War II, industrialist Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis.","actors": ["Liam Neeson", "Ralph Fiennes", "Ben Kingsley", "Caroline Goodall"] ,"director":" Steven Spielberg ","rating":"8.9","certificate":"R","genre": ["Biography", "Drama", "History"] } 59 | {"index":{"_index":"movies","_id":"9"}} 60 | {"title": "Inception","synopsis": "A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.","actors": ["Leonardo DiCaprio", "Joseph Gordon-Levitt", "Elliot Page", "Ken Watanabe"] ,"director":" Christopher Nolan ","rating":"8.8","certificate":"PG-13","genre": ["Action", "Adventure", "Sci-Fi"] } 61 | {"index":{"_index":"movies","_id":"10"}} 62 | {"title": "Fight Club","synopsis": "An insomniac office worker and a devil-may-care soap maker form an underground fight club that evolves into much more.","actors": ["Brad Pitt", "Edward Norton", "Meat Loaf", "Zach Grenier"] ,"director":" David Fincher ","rating":"8.8","certificate":"R","genre": "Drama"} 63 | {"index":{"_index":"movies","_id":"11"}} 64 | {"title": "The Lord of the Rings: The Fellowship of the Ring","synopsis": "A meek Hobbit from the Shire and eight companions set out on a journey to destroy the powerful One Ring and save Middle-earth from the Dark Lord Sauron.","actors": ["Elijah Wood", "Ian McKellen", "Orlando Bloom", "Sean Bean"] ,"director":" Peter Jackson ","rating":"8.8","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] } 65 | {"index":{"_index":"movies","_id":"12"}} 66 | {"title": "Forrest Gump","synopsis": "The presidencies of Kennedy and Johnson, the Vietnam War, the Watergate scandal and other historical events unfold from the perspective of an Alabama man with an IQ of 75, whose only desire is to be reunited with his childhood sweetheart.","actors": ["Tom Hanks", "Robin Wright", "Gary Sinise", "Sally Field"] ,"director":" Robert Zemeckis ","rating":"8.8","certificate":"PG-13","genre": ["Drama", "Romance"] } 67 | {"index":{"_index":"movies","_id":"13"}} 68 | {"title": "The Good, the Bad and the Ugly","synopsis": "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.","actors": ["Clint Eastwood", "Eli Wallach", "Lee Van Cleef", "Aldo Giuffrè"] ,"director":" Sergio Leone ","rating":"8.8","certificate":"R","genre": "Western"} 69 | {"index":{"_index":"movies","_id":"14"}} 70 | {"title": "The Lord of the Rings: The Two Towers","synopsis": "While Frodo and Sam edge closer to Mordor with the help of the shifty Gollum, the divided fellowship makes a stand against Sauron's new ally, Saruman, and his hordes of Isengard.","actors": ["Elijah Wood", "Ian McKellen", "Viggo Mortensen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":"8.7","certificate":"PG-13","genre": ["Action", "Adventure", "Drama"]} 71 | {"index":{"_index":"movies","_id":"15"}} 72 | {"title": "The Matrix","synopsis": "When a beautiful stranger leads computer hacker Neo to a forbidding underworld, he discovers the shocking truth--the life he knows is the elaborate deception of an evil cyber-intelligence.","actors": ["Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss", "Hugo Weaving"] ,"director":["Lana Wachowski", "Lilly Wachowski"] ,"rating":"8.7","certificate":"R","genre": ["Action", "Sci-Fi"] } 73 | {"index":{"_index":"movies","_id":"16"}} 74 | {"title": "Goodfellas","synopsis": "The story of Henry Hill and his life in the mob, covering his relationship with his wife Karen Hill and his mob partners Jimmy Conway and Tommy DeVito in the Italian-American crime syndicate.","actors": ["Robert De Niro", "Ray Liotta", "Joe Pesci", "Lorraine Bracco"] ,"director":" Martin Scorsese ","rating":"8.7","certificate":"R","genre": ["Biography", "Drama", "Crime"] } 75 | {"index":{"_index":"movies","_id":"17"}} 76 | {"title": "Star Wars: Episode V - The Empire Strikes Back","synopsis": "After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda, while his friends are pursued across the galaxy by Darth Vader and bounty hunter Boba Fett.","actors": ["Mark Hamill", "Harrison Ford", "Carrie Fisher", "Billy Dee Williams"] ,"director":" Irvin Kershner ","rating":"8.7","certificate":"PG-13","genre": ["Action", "Adventure", "Fantasy"] } 77 | {"index":{"_index":"movies","_id":"18"}} 78 | {"title": "One Flew Over the Cuckoo's Nest","synopsis": "A criminal pleads insanity and is admitted to a mental institution, where he rebels against the oppressive nurse and rallies up the scared patients.","actors": ["Jack Nicholson", "Louise Fletcher", "Michael Berryman", "Peter Brocco"] ,"director":" Milos Forman ","rating":"8.7","certificate":"R","genre": "Drama" } 79 | {"index":{"_index":"movies","_id":"19"}} 80 | {"title": "Parasite","synopsis": "Greed and class discrimination threaten the newly formed symbiotic relationship between the wealthy Park family and the destitute Kim clan.","actors": ["Kang-ho Song", "Sun-kyun Lee", "Yeo-jeong Cho", "Woo-sik Choi"] ,"director":" Bong Joon Ho ","rating":"8.6","certificate":"R","genre": ["Comedy", "Drama", "Thriller"] } 81 | {"index":{"_index":"movies","_id":"20"}} 82 | {"title": "Interstellar","synopsis": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.","actors": ["Matthew McConaughey", "Anne Hathaway", "Jessica Chastain", "Mackenzie Foy"] ,"director":" Christopher Nolan ","rating":"8.6","certificate":"PG-13","genre": ["Adventure", "Drama", "Sci-Fi"] } 83 | {"index":{"_index":"movies","_id":"21"}} 84 | {"title": "City of God","synopsis": "In the slums of Rio, two kids paths diverge as one struggles to become a photographer and the other a kingpin.","actors": ["Alexandre Rodrigues", "Leandro Firmino", "Matheus Nachtergaele", "Phellipe Haagensen"] ,"director": ["Fernando Meirelles", "Kátia Lund"] ,"rating":"8.6","certificate":"R","genre": ["Crime", "Drama"] } 85 | {"index":{"_index":"movies","_id":"22"}} 86 | {"title": "Spirited Away","synopsis": "During her family's move to the suburbs, a sullen 10-year-old girl wanders into a world ruled by gods, witches, and spirits, and where humans are changed into beasts.","actors": ["Daveigh Chase", "Suzanne Pleshette", "Miyu Irino", "Rumi Hiiragi"] ,"director":" Hayao Miyazaki ","rating":"8.6","certificate":"PG-13","genre": ["Animation", "Adventure", "Family"]} 87 | {"index":{"_index":"movies","_id":"23"}} 88 | {"title": "Saving Private Ryan","synopsis": "Following the Normandy Landings, a group of U.S. soldiers go behind enemy lines to retrieve a paratrooper whose brothers have been killed in action.","actors": ["Tom Hanks", "Matt Damon", "Tom Sizemore", "Edward Burns"] ,"director":" Steven Spielberg ","rating":"8.6","certificate":"R","genre": ["Drama", "War"] } 89 | {"index":{"_index":"movies","_id":"24"}} 90 | {"title": "The Green Mile","synopsis": "The lives of guards on Death Row are affected by one of their charges: a black man accused of child murder and rape, yet who has a mysterious gift.","actors": ["Tom Hanks", "Michael Clarke Duncan", "David Morse", "Bonnie Hunt"] ,"director":" Frank Darabont ","rating":"8.6","certificate":"R","genre": ["Crime", "Drama", "Fantasy"] } 91 | {"index":{"_index":"movies","_id":"25"}} 92 | {"title": "Life Is Beautiful","synopsis": "When an open-minded Jewish librarian and his son become victims of the Holocaust, he uses a perfect mixture of will, humor, and imagination to protect his son from the dangers around their camp.","actors": ["Roberto Benigni", "Nicoletta Braschi", "Giorgio Cantarini", "Giustino Durano"] ,"director":" Roberto Benigni ","rating":"8.6","certificate":"PG-13","genre": ["Comedy", "Drama", "Romance"]} 93 | 94 | # Searching for a title 95 | GET movies/_search 96 | { 97 | "query": { 98 | "match": { 99 | "title": "Godfather" 100 | } 101 | } 102 | } 103 | 104 | ## Query and filter context: 105 | # Query without scoring - query context by default 106 | GET movies/_search 107 | { 108 | "query": { 109 | "match": { 110 | "title": "Godfather" 111 | } 112 | } 113 | } 114 | 115 | # Filter context - no score returned 116 | GET movies/_search 117 | { 118 | "query": { 119 | "bool": { 120 | "filter": [ 121 | { 122 | "match": { 123 | "title": "Godfather" 124 | } 125 | } 126 | ] 127 | } 128 | } 129 | } 130 | #Another way to set the filter context 131 | GET movies/_search 132 | { 133 | "query": { 134 | "constant_score": { 135 | "filter": { 136 | "match": { 137 | "title": "Godfather" 138 | } 139 | } 140 | } 141 | } 142 | } 143 | 144 | # URI search 145 | # Search a movie by title 146 | GET movies/_search 147 | GET movies/_search?q=title:Godfather 148 | 149 | # Search a movie by multiple titles 150 | GET movies/_search?q=title:Godfather Knight Shawshank 151 | 152 | #Fetch a specific title AND an actor combination 153 | GET movies/_search?q=title:Knight AND actors:Bale 154 | 155 | #Fetch a specific title OR an actor combination 156 | GET movies/_search?q=title:Godfather actors:Bale 157 | 158 | # Setting a default_operator 159 | GET movies/_search?q=title:Godfather actors:Bale&default_operator=AND 160 | 161 | # Additional query parameters 162 | 163 | GET movies/_search?q=title:Knight actors:(bale AND ledger) rating:(>=9.0 AND <=9.5)&from=0&size=10&explain=true&sort=rating&default_operator=AND 164 | 165 | 166 | GET movies/_search?q=title:Godfather actors:(Brando OR Pacino) rating:(>=9.0 AND <=9.5)&from=0&size=10&explain=true&sort=rating&default_operator=AND 167 | 168 | GET movies/_search 169 | 170 | #Query String 171 | GET movies/_search 172 | { 173 | "query": { 174 | "query_string": { 175 | "default_field": "title", 176 | "query": "Knight Redemption Lord Pulp", 177 | "default_operator": "OR" 178 | } 179 | } 180 | } 181 | 182 | # Query DSL sample query 183 | GET movies/_search 184 | { 185 | "query": { 186 | "multi_match": { 187 | "query": "Lord", 188 | "fields": ["synopsis","title"] 189 | } 190 | } 191 | } 192 | 193 | GET movies/_search 194 | { 195 | "size": 0, 196 | "aggs": { 197 | "average_movie_rating": { 198 | "avg": { 199 | "field": "rating" 200 | } 201 | } 202 | } 203 | } 204 | 205 | # Leaf query 206 | GET movies/_search 207 | { 208 | "query": { 209 | "match_phrase": { 210 | "synopsis": "A meek hobbit from the shire and eight companions" 211 | } 212 | } 213 | } 214 | 215 | # Compound query example 216 | GET movies/_search 217 | { 218 | "query": { 219 | "bool": { 220 | "must": [ 221 | {"match": { 222 | "title": "Godfather" 223 | }} 224 | ], 225 | "must_not": [ 226 | { 227 | "range": { 228 | "rating": { 229 | "lt": 9.0 230 | } 231 | }} 232 | ], 233 | "should": [ 234 | { 235 | "match": { 236 | "actors": "Pacino" 237 | }} 238 | ], 239 | "filter": [ 240 | { 241 | "term": { 242 | "actors": "brando" 243 | } 244 | } 245 | ] 246 | } 247 | } 248 | } 249 | 250 | # Match query 251 | GET movies/_search 252 | { 253 | "query": { 254 | "match": { 255 | "director": "Francis" 256 | } 257 | } 258 | } 259 | 260 | ## Pagination 261 | 262 | # Query to fetch a specific number of results 263 | GET movies/_search 264 | { 265 | "size": 20, 266 | "query": { 267 | "match_all": {} 268 | } 269 | } 270 | 271 | #Resetting the 10k default size limit 272 | # The following query will result in exception 273 | # as the result window is too large (greater than 10k results) 274 | GET movies/_search 275 | { 276 | "size": 10001, 277 | "query": { 278 | "match_all": {} 279 | } 280 | } 281 | 282 | #Reset the max results setting 283 | PUT movies/_settings 284 | { 285 | "max_result_window":10001 286 | } 287 | 288 | # Paginated results using size and from 289 | GET movies/_search 290 | { 291 | "size": 100, 292 | "from": 3, 293 | "query": { 294 | "match_all": {} 295 | } 296 | } 297 | 298 | # Highlighting 299 | GET movies/_search 300 | { 301 | "_source": false, 302 | "query": { 303 | "term": { 304 | "title": { 305 | "value": "godfather" 306 | } 307 | } 308 | },"highlight": { 309 | "fields": { 310 | "title": {} 311 | } 312 | } 313 | } 314 | # Explanation 315 | GET movies/_search 316 | { 317 | "explain": true, 318 | "_source": false, 319 | "query": { 320 | "match": { 321 | "title": "Lord" 322 | } 323 | } 324 | } 325 | 326 | # Exactly same as above - explains the scores 327 | GET movies/_explain/14 328 | { 329 | "query":{ 330 | "match": { 331 | "title": "Lords" 332 | } 333 | } 334 | } 335 | 336 | ## Sorting 337 | 338 | # Sort by rating in ascending order 339 | GET movies/_search 340 | { 341 | "size": 10, 342 | "query": { 343 | "match": { 344 | "title": "Godfather" 345 | } 346 | }, 347 | "sort": [{ 348 | "rating": {"order": "asc"} 349 | } 350 | ] 351 | } 352 | 353 | # Sort by score (no sort - default by _score in desc) 354 | GET movies/_search 355 | { 356 | "size": 10, 357 | "query": { 358 | "match": { 359 | "title": "Godfather" 360 | } 361 | } 362 | } 363 | 364 | # Sort by score - mention the _score in sort 365 | GET movies/_search 366 | { 367 | "size": 10, 368 | "query": { 369 | "match": { 370 | "title": "Godfather" 371 | } 372 | }, 373 | "sort": [ 374 | "_score" 375 | ] 376 | } 377 | 378 | # Sort by _score in asc 379 | GET movies/_search 380 | { 381 | "size": 10, 382 | "query": { 383 | "match": { 384 | "title": "Godfather" 385 | } 386 | }, 387 | "sort": [ 388 | {"_score":{"order":"asc"}} 389 | ] 390 | } 391 | 392 | # Sort by a field desc 393 | GET movies/_search 394 | { 395 | "size": 10, 396 | "query": { 397 | "match": { 398 | "genre": "crime" 399 | } 400 | }, 401 | "sort": [ 402 | {"rating":{"order":"desc"}} 403 | ] 404 | } 405 | 406 | # Sort by multiple fields asc 407 | GET movies/_search 408 | { 409 | "track_scores":true, 410 | "size": 10, 411 | "query": { 412 | "match": { 413 | "genre": "crime" 414 | } 415 | }, 416 | "sort": [ 417 | {"rating":{"order":"asc"}}, 418 | {"release_date":{"order":"asc"}} 419 | ] 420 | } 421 | 422 | # Manipulating search responses 423 | # Suppressing the source document 424 | GET movies/_search 425 | { 426 | "_source": false, 427 | "query": { 428 | "match": { 429 | "certificate": "R" 430 | } 431 | } 432 | } 433 | # Selected fields 434 | GET movies/_search 435 | { 436 | "_source": false, 437 | "query": { 438 | "match": { 439 | "certificate": "R" 440 | } 441 | }, 442 | "fields": [ 443 | "title*", 444 | "rating" 445 | ] 446 | } 447 | 448 | # Source filtering 449 | GET movies/_search 450 | { 451 | "_source": ["title*","synopsis", "rating"], 452 | "query": { 453 | "match": { 454 | "certificate": "R" 455 | } 456 | } 457 | } 458 | 459 | # Source filtering with a script field 460 | GET movies/_search 461 | { 462 | "_source": ["title*","synopsis", "rating"], 463 | "query": { 464 | "match": { 465 | "certificate": "R" 466 | } 467 | }, 468 | "script_fields": { 469 | "top_rated_movie": { 470 | "script": { 471 | "lang": "painless", 472 | "source": "if (doc['rating'].value > 9.0) 'true'; else 'false'" 473 | } 474 | } 475 | } 476 | } 477 | 478 | # Source filtering using includes and excludes 479 | GET movies/_search 480 | { 481 | "_source": { 482 | "includes": ["title*","synopsis","genre"], 483 | "excludes": ["title.original"] 484 | }, 485 | "query": { 486 | "match": { 487 | "certificate": "R" 488 | } 489 | } 490 | } 491 | 492 | # Return everything except synoposis and actors 493 | GET movies/_search 494 | { 495 | "_source": { 496 | "excludes": ["synopsis","actors"] 497 | }, 498 | "query": { 499 | "match": { 500 | "certificate": "R" 501 | } 502 | } 503 | } 504 | 505 | ## Searching across multiple indices 506 | # Searching for Pacino movies across all indicies 507 | GET _search 508 | { 509 | "query": { 510 | "match": { 511 | "actors": "Pacino" 512 | } 513 | } 514 | } 515 | 516 | # Using _all to indicate every index in the cluster 517 | GET _all/_search 518 | { 519 | "query": { 520 | "match": { 521 | "actors": "Pacino" 522 | } 523 | } 524 | } 525 | 526 | # Use a wildcard to denote every index 527 | GET */_search 528 | { 529 | "query": { 530 | "match": { 531 | "actors": "Pacino" 532 | } 533 | } 534 | } 535 | ## Boosting indices 536 | # Index a document for this exercise 537 | 538 | PUT movies_top/_doc/1 539 | { 540 | "title": "The Shawshank Redemption", 541 | "synopsis": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.", 542 | "actors": [ 543 | "Tim Robbins", 544 | "Morgan Freeman", 545 | "Bob Gunton", 546 | "William Sadler" 547 | ], 548 | "director": " Frank Darabont ", 549 | "rating": "9.3", 550 | "certificate": "R", 551 | "genre": "Drama " 552 | } 553 | 554 | PUT movies_new/_doc/1 555 | { 556 | "title": "The Shawshank Redemption", 557 | "synopsis": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.", 558 | "actors": [ 559 | "Tim Robbins", 560 | "Morgan Freeman", 561 | "Bob Gunton", 562 | "William Sadler" 563 | ], 564 | "director": " Frank Darabont ", 565 | "rating": "9.3", 566 | "certificate": "R", 567 | "genre": "Drama " 568 | } 569 | 570 | GET movies*/_search 571 | { 572 | "query": { 573 | "match": { 574 | "title": "Redemption" 575 | } 576 | } 577 | } 578 | 579 | GET movies_new/_mapping 580 | GET movies*/_search 581 | { 582 | "indices_boost": [ 583 | { "movies": 0.1}, 584 | { "movies_new": 0}, 585 | { "movies_top": 2.0} 586 | ], 587 | "query": { 588 | "match": { 589 | "title": "Redemption" 590 | } 591 | } 592 | } 593 | 594 | 595 | GET movies/_search 596 | { 597 | "query": { 598 | "bool": { 599 | "must_not": [ 600 | { 601 | "match": { 602 | "title": "Godfather" 603 | } 604 | } 605 | ] 606 | } 607 | } 608 | } 609 | -------------------------------------------------------------------------------- /kibana_scripts/ch09_term_level_queries.txt: -------------------------------------------------------------------------------- 1 | DELETE movies 2 | # Creating movies index with explicit mapping 3 | PUT movies 4 | { 5 | "mappings": { 6 | "properties": { 7 | "title": { 8 | "type": "text", 9 | "fields": { 10 | "original": { 11 | "type": "keyword" 12 | } 13 | } 14 | }, 15 | "synopsis": { 16 | "type": "text", 17 | "fields": { 18 | "original": { 19 | "type": "keyword" 20 | } 21 | } 22 | }, 23 | "actors": { 24 | "type": "text", 25 | "fields": { 26 | "original": { 27 | "type": "keyword" 28 | } 29 | } 30 | }, 31 | "director": { 32 | "type": "text", 33 | "fields": { 34 | "original": { 35 | "type": "keyword" 36 | } 37 | } 38 | }, 39 | "rating": { 40 | "type": "half_float" 41 | }, 42 | "release_date": { 43 | "type": "date", 44 | "format": "dd-MM-yyyy" 45 | }, 46 | "certificate": { 47 | "type": "keyword", 48 | "fields": { 49 | "original": { 50 | "type": "keyword" 51 | } 52 | } 53 | }, 54 | "genre": { 55 | "type": "text", 56 | "index_prefixes":{}, 57 | "fields": { 58 | "original": { 59 | "type": "keyword" 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | # Insert the movies sample data 67 | ## Copy the contents of datasets/top-movies.json and index the movies using bulk API 68 | 69 | POST _bulk 70 | {"index":{"_index":"movies","_id":"1"}} 71 | {"title": "The Shawshank Redemption","synopsis": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.","actors": ["Tim Robbins", "Morgan Freeman", "Bob Gunton", "William Sadler"] ,"director":" Frank Darabont ","rating":9.3,"certificate":"R","genre": "Drama ","release_date":"17-02-1995"} 72 | {"index":{"_index":"movies","_id":"2"}} 73 | {"title": "The Godfather","synopsis": "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.","actors": ["Marlon Brando", "Al Pacino", "James Caan", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":9.2,"certificate":"R","genre": ["Crime", "Drama"] ,"release_date":"14-03-1972"} 74 | {"index":{"_index":"movies","_id":"3"}} 75 | {"title": "The Dark Knight","synopsis": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, Batman must accept one of the greatest psychological and physical tests of his ability to fight injustice.","actors": ["Christian Bale", "Heath Ledger", "Aaron Eckhart", "Michael Caine"] ,"director":" Christopher Nolan ","rating":9.0,"certificate":"PG-13","genre": ["Action", "Crime", "Drama"] ,"release_date":"18-07-2008"} 76 | {"index":{"_index":"movies","_id":"4"}} 77 | {"title": "The Godfather: Part II","synopsis": "The early life and career of Vito Corleone in 1920s New York City is portrayed, while his son, Michael, expands and tightens his grip on the family crime syndicate.","actors": ["Al Pacino", "Robert De Niro", "Robert Duvall", "Diane Keaton"] ,"director":" Francis Ford Coppola ","rating":9.0,"certificate":"R","genre": ["Crime", "Drama"] ,"release_date":"20-12-1974"} 78 | {"index":{"_index":"movies","_id":"5"}} 79 | {"title": "12 Angry Men","synopsis": "A jury holdout attempts to prevent a miscarriage of justice by forcing his colleagues to reconsider the evidence.","actors": ["Henry Fonda", "Lee J. Cobb", "Martin Balsam", " John Fiedler"] ,"director":" Sidney Lumet ","rating":9.0,"certificate":"Approved","genre": ["Crime", "Drama"],"release_date":"10-04-1957" } 80 | {"index":{"_index":"movies","_id":"6"}} 81 | {"title": "The Lord of the Rings: The Return of the King","synopsis": "Gandalf and Aragorn lead the World of Men against Saurons's army to draw his gaze from Frodo and Sam as they approach Mount Doom with the One Ring.","actors": ["Elijah Wood", "Viggo Mortensen", "Ian McKellen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":8.9,"certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] ,"release_date":"06-02-2004"} 82 | {"index":{"_index":"movies","_id":"7"}} 83 | {"title": "Pulp Fiction","synopsis": "The lives of two mob hitmen, a boxer, a gangster and his wife, and a pair of diner bandits intertwine in four tales of violence and redemption.","actors": ["John Travolta", "Uma Thurman", "Samuel L. Jackson", "Bruce Willis"] ,"director":" Quentin Tarantino ","rating":8.9,"certificate":"R","genre": ["Crime", "Drama"] ,"release_date":"14-10-1994"} 84 | {"index":{"_index":"movies","_id":"8"}} 85 | {"title": "Schindler's List","synopsis": "In German-occupied Poland during World War II, industrialist Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis.","actors": ["Liam Neeson", "Ralph Fiennes", "Ben Kingsley", "Caroline Goodall"] ,"director":" Steven Spielberg ","rating":8.9,"certificate":"R","genre": ["Biography", "Drama", "History"] ,"release_date":"04-07-1994"} 86 | {"index":{"_index":"movies","_id":"9"}} 87 | {"title": "Inception","synopsis": "A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a C.E.O.","actors": ["Leonardo DiCaprio", "Joseph Gordon-Levitt", "Elliot Page", "Ken Watanabe"] ,"director":" Christopher Nolan ","rating":8.8,"certificate":"PG-13","genre": ["Action", "Adventure", "Sci-Fi"] ,"release_date":"16-07-2010"} 88 | {"index":{"_index":"movies","_id":"10"}} 89 | {"title": "Fight Club","synopsis": "An insomniac office worker and a devil-may-care soap maker form an underground fight club that evolves into much more.","actors": ["Brad Pitt", "Edward Norton", "Meat Loaf", "Zach Grenier"] ,"director":" David Fincher ","rating":8.8,"certificate":"R","genre": "Drama","release_date":"11-11-1999"} 90 | {"index":{"_index":"movies","_id":"11"}} 91 | {"title": "The Lord of the Rings: The Fellowship of the Ring","synopsis": "A meek Hobbit from the Shire and eight companions set out on a journey to destroy the powerful One Ring and save Middle-earth from the Dark Lord Sauron.","actors": ["Elijah Wood", "Ian McKellen", "Orlando Bloom", "Sean Bean"] ,"director":" Peter Jackson ","rating":8.8,"certificate":"PG-13","genre": ["Action", "Adventure", "Drama"] ,"release_date":"15-03-2002"} 92 | {"index":{"_index":"movies","_id":"12"}} 93 | {"title": "Forrest Gump","synopsis": "The presidencies of Kennedy and Johnson, the Vietnam War, the Watergate scandal and other historical events unfold from the perspective of an Alabama man with an IQ of 75, whose only desire is to be reunited with his childhood sweetheart.","actors": ["Tom Hanks", "Robin Wright", "Gary Sinise", "Sally Field"] ,"director":" Robert Zemeckis ","rating":8.8,"certificate":"PG-13","genre": ["Drama", "Romance"] ,"release_date":"06-07-1994"} 94 | {"index":{"_index":"movies","_id":"13"}} 95 | {"title": "The Good, the Bad and the Ugly","synopsis": "A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.","actors": ["Clint Eastwood", "Eli Wallach", "Lee Van Cleef", "Aldo Giuffrè"] ,"director":" Sergio Leone ","rating":8.8,"certificate":"R","genre": "Western","release_date":"23-12-1966"} 96 | {"index":{"_index":"movies","_id":"14"}} 97 | {"title": "The Lord of the Rings: The Two Towers","synopsis": "While Frodo and Sam edge closer to Mordor with the help of the shifty Gollum, the divided fellowship makes a stand against Sauron's new ally, Saruman, and his hordes of Isengard.","actors": ["Elijah Wood", "Ian McKellen", "Viggo Mortensen", "Orlando Bloom"] ,"director":" Peter Jackson ","rating":8.7,"certificate":"PG-13","genre": ["Action", "Adventure", "Drama"],"release_date":"28-03-2003"} 98 | {"index":{"_index":"movies","_id":"15"}} 99 | {"title": "The Matrix","synopsis": "When a beautiful stranger leads computer hacker Neo to a forbidding underworld, he discovers the shocking truth--the life he knows is the elaborate deception of an evil cyber-intelligence.","actors": ["Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss", "Hugo Weaving"] ,"director":["Lana Wachowski", "Lilly Wachowski"] ,"rating":8.7,"certificate":"R","genre": ["Action", "Sci-Fi"] ,"release_date":"16-05-2003"} 100 | {"index":{"_index":"movies","_id":"16"}} 101 | {"title": "Goodfellas","synopsis": "The story of Henry Hill and his life in the mob, covering his relationship with his wife Karen Hill and his mob partners Jimmy Conway and Tommy DeVito in the Italian-American crime syndicate.","actors": ["Robert De Niro", "Ray Liotta", "Joe Pesci", "Lorraine Bracco"] ,"director":" Martin Scorsese ","rating":8.7,"certificate":"R","genre": ["Biography", "Drama", "Crime"],"release_date":"19-09-1990" } 102 | {"index":{"_index":"movies","_id":"17"}} 103 | {"title": "Star Wars: Episode V - The Empire Strikes Back","synopsis": "After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda, while his friends are pursued across the galaxy by Darth Vader and bounty hunter Boba Fett.","actors": ["Mark Hamill", "Harrison Ford", "Carrie Fisher", "Billy Dee Williams"] ,"director":" Irvin Kershner ","rating":8.7,"certificate":"PG-13","genre": ["Action", "Adventure", "Fantasy"] ,"release_date":"21-05-1980"} 104 | {"index":{"_index":"movies","_id":"18"}} 105 | {"title": "One Flew Over the Cuckoo's Nest","synopsis": "A criminal pleads insanity and is admitted to a mental institution, where he rebels against the oppressive nurse and rallies up the scared patients.","actors": ["Jack Nicholson", "Louise Fletcher", "Michael Berryman", "Peter Brocco"] ,"director":" Milos Forman ","rating":8.7,"certificate":"R","genre": "Drama" ,"release_date":"19-11-1975"} 106 | {"index":{"_index":"movies","_id":"19"}} 107 | {"title": "Parasite","synopsis": "Greed and class discrimination threaten the newly formed symbiotic relationship between the wealthy Park family and the destitute Kim clan.","actors": ["Kang-ho Song", "Sun-kyun Lee", "Yeo-jeong Cho", "Woo-sik Choi"] ,"director":" Bong Joon Ho ","rating":8.6,"certificate":"R","genre": ["Comedy", "Drama", "Thriller"] ,"release_date":"30-05-2019"} 108 | {"index":{"_index":"movies","_id":"20"}} 109 | {"title": "Interstellar","synopsis": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.","actors": ["Matthew McConaughey", "Anne Hathaway", "Jessica Chastain", "Mackenzie Foy"] ,"director":" Christopher Nolan ","rating":8.6,"certificate":"PG-13","genre": ["Adventure", "Drama", "Sci-Fi"] ,"release_date":"07-11-2014"} 110 | {"index":{"_index":"movies","_id":"21"}} 111 | {"title": "City of God","synopsis": "In the slums of Rio, two kids paths diverge as one struggles to become a photographer and the other a kingpin.","actors": ["Alexandre Rodrigues", "Leandro Firmino", "Matheus Nachtergaele", "Phellipe Haagensen"] ,"director": ["Fernando Meirelles", "Kátia Lund"] ,"rating":8.6,"certificate":"R","genre": ["Crime", "Drama"],"release_date":"30-08-2002" } 112 | {"index":{"_index":"movies","_id":"22"}} 113 | {"title": "Spirited Away","synopsis": "During her family's move to the suburbs, a sullen 10-year-old girl wanders into a world ruled by gods, witches, and spirits, and where humans are changed into beasts.","actors": ["Daveigh Chase", "Suzanne Pleshette", "Miyu Irino", "Rumi Hiiragi"] ,"director":" Hayao Miyazaki ","rating":8.6,"certificate":"PG-13","genre": ["Animation", "Adventure", "Family"],"release_date":"20-07-2001"} 114 | {"index":{"_index":"movies","_id":"23"}} 115 | {"title": "Saving Private Ryan","synopsis": "Following the Normandy Landings, a group of U.S. soldiers go behind enemy lines to retrieve a paratrooper whose brothers have been killed in action.","actors": ["Tom Hanks", "Matt Damon", "Tom Sizemore", "Edward Burns"] ,"director":" Steven Spielberg ","rating":8.6,"certificate":"R","genre": ["Drama", "War"] ,"release_date":"21-07-1998"} 116 | {"index":{"_index":"movies","_id":"24"}} 117 | {"title": "The Green Mile","synopsis": "The lives of guards on Death Row are affected by one of their charges: a black man accused of child murder and rape, yet who has a mysterious gift.","actors": ["Tom Hanks", "Michael Clarke Duncan", "David Morse", "Bonnie Hunt"] ,"director":" Frank Darabont ","rating":8.6,"certificate":"R","genre": ["Crime", "Drama", "Fantasy"] ,"release_date":"06-12-1999"} 118 | {"index":{"_index":"movies","_id":"25"}} 119 | {"title": "Life Is Beautiful","synopsis": "When an open-minded Jewish librarian and his son become victims of the Holocaust, he uses a perfect mixture of will, humor, and imagination to protect his son from the dangers around their camp.","actors": ["Roberto Benigni", "Nicoletta Braschi", "Giorgio Cantarini", "Giustino Durano"] ,"director":" Roberto Benigni ","rating":8.6,"certificate":"PG-13","genre": ["Comedy", "Drama", "Romance"],"release_date":"14-09-2012"} 120 | 121 | 122 | # Fetching the movies with a specific rating 123 | GET movies/_search 124 | { 125 | "query": { 126 | "term": { 127 | "certificate": "R" 128 | } 129 | } 130 | } 131 | 132 | # Fetching the movies by lowercasing the rating 133 | # No results returned 134 | GET movies/_search 135 | { 136 | "query": { 137 | "term": { 138 | "certificate": "r" 139 | } 140 | } 141 | } 142 | # This term query wouldn't return the results 143 | GET movies/_search 144 | { 145 | "query": { 146 | "term": { 147 | "title": "The Godfather" 148 | } 149 | } 150 | } 151 | 152 | # Terms query 153 | GET movies/_search 154 | { 155 | "query": { 156 | "terms": { 157 | "certificate": ["PG-13","R"] 158 | } 159 | } 160 | } 161 | 162 | # Change the max term count property 163 | PUT movies/_settings 164 | { 165 | "index":{ 166 | "max_terms_count":10 167 | } 168 | } 169 | 170 | # Terms lookup 171 | DELETE classic_movies 172 | 173 | PUT classic_movies 174 | { 175 | "mappings": { 176 | "properties": { 177 | "title": { 178 | "type": "text" 179 | }, 180 | "director": { 181 | "type": "keyword" 182 | } 183 | } 184 | } 185 | } 186 | 187 | # Index three docs 188 | PUT classic_movies/_doc/1 189 | { 190 | "title":"Jaws", 191 | "director":"Steven Spielberg" 192 | } 193 | 194 | PUT classic_movies/_doc/2 195 | { 196 | "title":"Jaws II", 197 | "director":"Jeannot Szwarc" 198 | } 199 | 200 | PUT classic_movies/_doc/3 201 | { 202 | "title":"Ready Player One", 203 | "director":"Steven Spielberg" 204 | } 205 | 206 | # Search for terms with director matching with the "path" value 207 | # from "classic_movies" index for a document with an ID as 3 (which is "Steven Spielberg) 208 | GET classic_movies/_search 209 | { 210 | "query": { 211 | "terms": { 212 | "director": { 213 | "index":"classic_movies", 214 | "id":"3", 215 | "path":"director" 216 | } 217 | } 218 | } 219 | } 220 | 221 | # This query to fetches two movies directored by Speilberg 222 | 223 | # IDs query 224 | GET movies/_search 225 | { 226 | "query": { 227 | "ids": { 228 | "values": [10,4,6,8] 229 | } 230 | } 231 | } 232 | 233 | # Terms query fetching IDs 234 | GET movies/_search 235 | { 236 | "query": { 237 | "terms": { 238 | "_id":[10,4,6,8] 239 | } 240 | } 241 | } 242 | 243 | # Exists query 244 | GET movies/_search 245 | { 246 | "query": { 247 | "exists": { 248 | "field": "_id" 249 | } 250 | } 251 | } 252 | 253 | GET movies/_search 254 | { 255 | "query": { 256 | "exists": { 257 | "field": "title" 258 | } 259 | } 260 | } 261 | 262 | #Fetching documents that miss a field by using bool query 263 | 264 | PUT top_secret_files/_doc/1 265 | { 266 | "code":"Flying Bird", 267 | "confidential":true 268 | } 269 | 270 | PUT top_secret_files/_doc/2 271 | { 272 | "code":"Cold Rock" 273 | } 274 | 275 | GET top_secret_files/_search 276 | { 277 | "query": { 278 | "bool": { 279 | "must_not": [ 280 | { 281 | "exists": { 282 | "field": "confidential" 283 | } 284 | } 285 | ] 286 | } 287 | } 288 | } 289 | 290 | # Range query 291 | GET movies/_search 292 | { 293 | "query": { 294 | "range": { 295 | "rating": { 296 | "gte": 9.0, 297 | "lte": 9.5 298 | } 299 | } 300 | } 301 | } 302 | 303 | # Fetch movies after 1970 and sort them in asc order 304 | GET movies/_search 305 | { 306 | "query": { 307 | "range": { 308 | "release_date": { 309 | "gte": "01-01-1970" 310 | } 311 | } 312 | }, 313 | "sort": [ 314 | { 315 | "release_date": { 316 | "order": "asc" 317 | } 318 | } 319 | ] 320 | } 321 | 322 | # Range query with date math 323 | # Before 13th Feb 1995 324 | GET movies/_search 325 | { 326 | "query": { 327 | "range": { 328 | "release_date": { 329 | "lte": "15-02-1995||-2d" 330 | } 331 | } 332 | } 333 | } 334 | 335 | # Released after 3rd march 2019 336 | GET movies/_search 337 | { 338 | "query": { 339 | "range": { 340 | "release_date": { 341 | "gte": "01-03-2019||-2d" 342 | } 343 | } 344 | } 345 | } 346 | # Before 15-March-2022 347 | GET movies/_search 348 | { 349 | "query": { 350 | "range": { 351 | "release_date": { 352 | "lte": "17-03-2022||-2d" 353 | } 354 | } 355 | } 356 | } 357 | 358 | # Range query with date match using now 359 | # Movies from last 4 years 360 | GET movies/_search 361 | { 362 | "query": { 363 | "range": { 364 | "release_date": { 365 | "gte": "now-4y" 366 | } 367 | } 368 | } 369 | } 370 | 371 | # Between now and 4 years ago 372 | GET movies/_search 373 | { 374 | "query": { 375 | "range": { 376 | "release_date": { 377 | "gte": "now-4y", 378 | "lte":"now" 379 | } 380 | } 381 | } 382 | } 383 | 384 | # Wildcard Query with a wildcard at the end 385 | GET movies/_search 386 | { 387 | "query": { 388 | "wildcard": { 389 | "title": { 390 | "value": "god*" 391 | } 392 | } 393 | } 394 | } 395 | 396 | # Wildcard Query with a wildcard in middle 397 | GET movies/_search 398 | { 399 | "_source": false, 400 | "query": { 401 | "wildcard": { 402 | "title": { 403 | "value": "g*d" 404 | } 405 | } 406 | }, 407 | "highlight": { 408 | "fields": { 409 | "title": {} 410 | } 411 | } 412 | } 413 | 414 | GET movies/_search 415 | { 416 | 417 | "query": { 418 | "wildcard": { 419 | "title.original": { 420 | "value": "The God*" 421 | } 422 | } 423 | }, 424 | "highlight": { 425 | "fields": { 426 | "title": {} 427 | } 428 | } 429 | } 430 | 431 | # Switch off the expensive queries 432 | PUT _cluster/settings 433 | { 434 | "transient": { 435 | "search.allow_expensive_queries": "false" 436 | } 437 | } 438 | GET movies/_mapping 439 | 440 | # Prefix query 441 | GET movies/_search 442 | { 443 | "query": { 444 | "prefix": { 445 | "genre.original": { 446 | "value": "Ad" 447 | } 448 | } 449 | },"highlight": { 450 | "fields": {"genre.original": {}} 451 | } 452 | } 453 | 454 | # Searching for actors with "Mar" as prefix 455 | GET movies/_search 456 | { 457 | "_source": false, 458 | "query": { 459 | "prefix": { 460 | "actors.original": { 461 | "value": "Mar" 462 | } 463 | } 464 | }, 465 | "highlight": { 466 | "fields": { 467 | "actors.original": {} 468 | } 469 | } 470 | } 471 | 472 | #Index prefixes 473 | PUT boxoffice_hit_movies 474 | { 475 | "mappings": { 476 | "properties": { 477 | "title":{ 478 | "type": "text", 479 | "index_prefixes":{} 480 | } 481 | } 482 | } 483 | } 484 | 485 | PUT boxoffice_hit_movies/_doc/1 486 | { 487 | "title":"Gladiator" 488 | } 489 | 490 | GET boxoffice_hit_movies/_search 491 | { 492 | "query": { 493 | "prefix": { 494 | "title": { 495 | "value": "gla" 496 | } 497 | } 498 | } 499 | } 500 | 501 | #Index prefixes with custom prefix settings 502 | PUT boxoffice_hit_movies_custom_prefix_sizes 503 | { 504 | "mappings": { 505 | "properties": { 506 | "title":{ 507 | "type": "text", 508 | "index_prefixes":{ 509 | "min_chars":4, 510 | "max_chars":10 511 | } 512 | } 513 | } 514 | } 515 | } 516 | 517 | # Fuzzy query with edit distance of 1 518 | GET movies/_search 519 | { 520 | "query": { 521 | "fuzzy": { 522 | "genre": { 523 | "value": "rama", 524 | "fuzziness": 1 525 | } 526 | } 527 | }, 528 | "highlight": { 529 | "fields": { 530 | "genre": {} 531 | } 532 | } 533 | } 534 | 535 | # Fuzzy query with dropping off middle letter 536 | GET movies/_search 537 | { 538 | "query": { 539 | "fuzzy": { 540 | "genre": { 541 | "value": "drma", 542 | "fuzziness": 1 543 | } 544 | } 545 | } 546 | } 547 | 548 | # Fuzzy query that has two letters missing 549 | GET movies/_search 550 | { 551 | "query": { 552 | "fuzzy": { 553 | "genre": { 554 | "value": "ama", 555 | "fuzziness": 2 556 | } 557 | } 558 | } 559 | } 560 | -------------------------------------------------------------------------------- /kibana_scripts/ch10_full_text_queries.txt: -------------------------------------------------------------------------------- 1 | # Full-text queries 2 | # BULK import books 3 | ## Copy the datasets/books.txt file into Kibana's DevTools and execute the bulk update 4 | 5 | # Match queries 6 | 7 | ##Match all query 8 | GET books/_search 9 | { 10 | "query": { 11 | "match_all": {} 12 | } 13 | } 14 | 15 | GET books/_search 16 | { 17 | "query": { 18 | "match": { 19 | "author": "Cay" 20 | } 21 | } 22 | } 23 | 24 | # Match query searching Java titles 25 | GET books/_search 26 | { 27 | "query": { 28 | "match": { 29 | "title": "Java" 30 | } 31 | } 32 | } 33 | 34 | # Match query searching for a set of words (like a sentence) 35 | GET books/_search 36 | { 37 | "query": { 38 | "match": { 39 | "title": { 40 | "query": "Java Complete Guide" 41 | } 42 | } 43 | }, 44 | "highlight": { 45 | "fields": { 46 | "title": {} 47 | } 48 | } 49 | } 50 | 51 | # Same as above query but specifying OR operator explicitly 52 | GET books/_search 53 | { 54 | "query": { 55 | "match": { 56 | "title": { 57 | "query": "Java Complete Guide", 58 | "operator": "OR" 59 | } 60 | } 61 | } 62 | } 63 | 64 | # Specifying AND operator explicitly 65 | GET books/_search 66 | { 67 | "query": { 68 | "match": { 69 | "title": { 70 | "query": "Java Complete Guide", 71 | "operator": "AND" 72 | } 73 | } 74 | } 75 | } 76 | 77 | # Matching at least two words 78 | GET books/_search 79 | { 80 | "query": { 81 | "match": { 82 | "title": { 83 | "query": "Java Complete Guide", 84 | "operator": "OR", 85 | "minimum_should_match": 2 86 | } 87 | } 88 | } 89 | } 90 | 91 | # Matching on an incorrect title (spelling mistake) - no results 92 | GET books/_search 93 | { 94 | "query": { 95 | "match": { 96 | "title": { 97 | "query": "Kava" 98 | } 99 | } 100 | } 101 | } 102 | 103 | # Matching on an incorrect title (spelling mistake) - with fuzziness- postive results 104 | GET books/_search 105 | { 106 | "query": { 107 | "match": { 108 | "title": { 109 | "query": "Kava", 110 | "fuzziness": 1 111 | } 112 | } 113 | } 114 | } 115 | 116 | # Match phrase query 117 | GET books/_search 118 | { 119 | "query": { 120 | "match_phrase": { 121 | "synopsis": "book for every Java programmer" 122 | } 123 | } 124 | } 125 | 126 | # Match phrase query with slop - missing one word 127 | GET books/_search 128 | { 129 | "query": { 130 | "match_phrase": { 131 | "synopsis": { 132 | "query": "book every Java programmer", 133 | "slop": 1 134 | } 135 | } 136 | } 137 | } 138 | 139 | # Match phrase query with jumbled up words will not work - even with slop 140 | GET books/_search 141 | { 142 | "query": { 143 | "match_phrase": { 144 | "synopsis": { 145 | "query": "for every Java programmer book", 146 | "slop": 1 147 | } 148 | } 149 | } 150 | } 151 | 152 | ##Match all query with a pre-defined score 153 | GET books/_search 154 | { 155 | "query": { 156 | "match_all": { 157 | "boost": 2 158 | } 159 | } 160 | } 161 | 162 | # Match phrase prefix 163 | GET books/_search 164 | { 165 | "query": { 166 | "match_phrase_prefix": { 167 | "tags": { 168 | "query": "concepts and found" 169 | } 170 | } 171 | }, 172 | "highlight": { 173 | "fields": { 174 | "tags": {} 175 | } 176 | } 177 | } 178 | # Match phrase prefix with slop - omitting "and" 179 | GET books/_search 180 | { 181 | "query": { 182 | "match_phrase_prefix": { 183 | "tags": { 184 | "query": "concepts found", 185 | "slop":1 186 | } 187 | } 188 | } 189 | } 190 | 191 | # Multi-match query 192 | GET books/_search 193 | { 194 | "_source": false, 195 | "query": { 196 | "multi_match": { 197 | "query": "Java", 198 | "fields": [ 199 | "title", 200 | "synopsis", 201 | "tags" 202 | ] 203 | } 204 | }, 205 | "highlight": { 206 | "fields": { 207 | "title": {}, 208 | "tags": {} 209 | } 210 | } 211 | } 212 | 213 | # Best fields 214 | GET books/_search 215 | { 216 | "_source": false, 217 | "query": { 218 | "multi_match": { 219 | "query": "Design Patterns", 220 | "type": "best_fields", 221 | "fields": ["title","synopsis"] 222 | } 223 | }, "highlight": { 224 | "fields": { 225 | "tags": {}, 226 | "title": {} 227 | } 228 | } 229 | } 230 | 231 | # Best fields - with a tie breaker 232 | GET books/_search 233 | { 234 | "_source": false, 235 | "query": { 236 | "multi_match": { 237 | "query": "Design Patterns", 238 | "type": "best_fields", 239 | "fields": ["title","synopsis"], 240 | "tie_breaker": 0.5 241 | } 242 | }, "highlight": { 243 | "fields": { 244 | "tags": {}, 245 | "title": {} 246 | } 247 | } 248 | } 249 | # 6.9938974 + 0.5 *(2.9220228 2.7801032 2.6008778) 250 | 251 | # dis_max query 252 | GET books/_search 253 | { 254 | "_source": false, 255 | "query": { 256 | "dis_max": { 257 | "queries": [ 258 | {"match": {"title": "Design Patterns"}}, 259 | {"match": {"synopsis": "Design Patterns"}}] 260 | } 261 | } 262 | } 263 | 264 | # dis_max query 265 | GET books/_search 266 | { 267 | "_source": false, 268 | "query": { 269 | "dis_max": { 270 | "queries": [ 271 | {"match": {"title": "Design Patterns"}}, 272 | {"match": {"synopsis": "Design Patterns"}}], 273 | "tie_breaker": 0.5 274 | } 275 | }, 276 | "highlight": { 277 | "fields": { 278 | "title": {}, 279 | "synopsis": {}, 280 | "tags": {} 281 | } 282 | } 283 | } 284 | 285 | # Boosting individual queries 286 | GET books/_search 287 | { 288 | "query": { 289 | "multi_match": { 290 | "query": "C# guide", 291 | "fields": ["title^2", "tags"] 292 | } 293 | } 294 | } 295 | 296 | # Query string 297 | GET books/_search 298 | { 299 | "query": { 300 | "query_string": { 301 | "query": "author:Bert AND edition:2 and release_date>=2000-01-01" 302 | } 303 | } 304 | } 305 | 306 | # Query string with a no field specified 307 | GET books/_search 308 | { 309 | "query": { 310 | "query_string": { 311 | "query": "Patterns" 312 | } 313 | }, 314 | "highlight": { 315 | "fields": { 316 | "title": {}, 317 | "synopsis": {}, 318 | "tags": {} 319 | } 320 | } 321 | } 322 | 323 | # Query string across multiple fields 324 | GET books/_search 325 | { 326 | "query": { 327 | "query_string": { 328 | "query": "Patterns", 329 | "fields": ["title","synopsis","tags"] 330 | } 331 | } 332 | } 333 | 334 | # Query string with a default field 335 | GET books/_search 336 | { 337 | "query": { 338 | "query_string": { 339 | "query": "Design Patterns", 340 | "default_field": "title" 341 | } 342 | } 343 | } 344 | 345 | # Query string with an AND operator 346 | GET books/_search 347 | { 348 | "query": { 349 | "query_string": { 350 | "query": "Design Patterns", 351 | "default_field": "title", 352 | "default_operator": "AND" 353 | } 354 | } 355 | } 356 | 357 | # Query string with a phrase 358 | GET books/_search 359 | { 360 | "query": { 361 | "query_string": { 362 | "query": "\"making the code better\"", 363 | "default_field": "synopsis" 364 | } 365 | } 366 | } 367 | 368 | # Query string with a phrase and a slop 369 | GET books/_search 370 | { 371 | "query": { 372 | "query_string": { 373 | "query": "\"making code better\"", 374 | "default_field": "synopsis", 375 | "phrase_slop": 1 376 | } 377 | } 378 | } 379 | 380 | # Query string with a fuzziness 381 | GET books/_search 382 | { 383 | "query": { 384 | "query_string": { 385 | "query": "Pattenrs~", 386 | "default_field": "title" 387 | } 388 | } 389 | } 390 | 391 | # Query string with a fuzziness with one edit distance 392 | GET books/_search 393 | { 394 | "query": { 395 | "query_string": { 396 | "query": "Pattenrs~1", 397 | "default_field": "title" 398 | } 399 | } 400 | } 401 | 402 | 403 | # Query string with a fuzziness with two corrections 404 | GET books/_search 405 | { 406 | "query": { 407 | "query_string": { 408 | "query": "tterns~", 409 | "default_field": "title" 410 | } 411 | } 412 | } 413 | 414 | # Illegal query 415 | GET books/_search 416 | { 417 | "query": { 418 | "query_string": { 419 | "query": "title::Java " 420 | } 421 | } 422 | } 423 | 424 | # Illegal query 425 | GET books/_search 426 | { 427 | "query": { 428 | "query_string": { 429 | "query": "title:Java\"" 430 | } 431 | } 432 | } 433 | 434 | # Simple query string 435 | GET books/_search 436 | { 437 | "query": { 438 | "simple_query_string": { 439 | "query": "Java + Cay" 440 | } 441 | } 442 | } 443 | 444 | # Simple query string - no issue with the incorrect syntax 445 | GET books/_search 446 | { 447 | "query": { 448 | "simple_query_string": { 449 | "query": "title:Java\"" 450 | } 451 | } 452 | } 453 | 454 | # Combined fields 455 | GET books/_search 456 | { 457 | "query": { 458 | "simple_query_string":{ 459 | "query":"Java", 460 | "fields":["title","synopsis"] 461 | } 462 | } 463 | } 464 | # Combined fields 465 | GET books/_search 466 | { 467 | "query": { 468 | "combined_fields":{ 469 | "query":"Java", 470 | "fields":["title","synopsis"] 471 | } 472 | } 473 | } 474 | -------------------------------------------------------------------------------- /kibana_scripts/ch13_aggregations.txt: -------------------------------------------------------------------------------- 1 | # Aggregations 2 | 3 | ## Bulk indexing TV sales 4 | 5 | PUT tv_sales/_bulk 6 | {"index":{"_id":"1"}} 7 | {"brand": "Samsung","name":"UHD TV","size_inches":65,"price_gbp":1400,"sales":17} 8 | {"index":{"_id":"2"}} 9 | {"brand":"Samsung","name":"UHD TV","size_inches":45,"price_gbp":1000,"sales":11} 10 | {"index":{"_id":"3"}} 11 | {"brand":"Samsung","name":"UHD TV","size_inches":23,"price_gbp":999,"sales":14} 12 | {"index":{"_id":"4"}} 13 | {"brand":"LG","name":"8K TV","size_inches":65,"price_gbp":1499,"sales":13} 14 | {"index":{"_id":"5"}} 15 | { "brand":"LG","name":"4K TV","size_inches":55,"price_gbp":1100,"sales":31} 16 | {"index":{"_id":"6"}} 17 | {"brand":"Philips","name":"8K TV","size_inches":65,"price_gbp":1800,"sales":23} 18 | {"index":{"_id":"7"}} 19 | {"name":"8K TV","size_inches":65,"price_gbp":2000,"sales":23} 20 | {"index":{"_id":"9"}} 21 | {"name":"8K TV","size_inches":65,"price_gbp":2000,"sales":23,"best_seller":true} 22 | {"index":{"_id":"10"}} 23 | {"name":"4K TV","size_inches":75,"price_gbp":2200,"sales":14,"best_seller":false} 24 | 25 | # METRIC Aggregations 26 | 27 | # Finding the number of documents using value_count metric 28 | GET tv_sales/_search 29 | { 30 | "size": 0, 31 | "aggs": { 32 | "total-values": { 33 | "value_count": { 34 | "field": "brand.keyword" 35 | } 36 | } 37 | } 38 | } 39 | 40 | # Finding the average price of the mobile 41 | GET tv_sales/_search 42 | { 43 | "size": 0, 44 | "aggs": { 45 | "tv_average_price": { 46 | "avg": { 47 | "field": "price_gbp" 48 | } 49 | } 50 | } 51 | } 52 | 53 | #Average sales 54 | 55 | GET tv_sales/_search 56 | { 57 | "size": 0, 58 | "aggs": { 59 | "average_price": { 60 | "avg": { 61 | "field": "sales" 62 | } 63 | } 64 | } 65 | } 66 | 67 | # Sum of all the TVs 68 | GET tv_sales/_search 69 | { 70 | "size": 0, 71 | "aggs": { 72 | "tv_total_price": { 73 | "sum": { 74 | "field": "price_gbp" 75 | } 76 | } 77 | } 78 | } 79 | 80 | # Top price of a TV amongst all TVs 81 | GET tv_sales/_search 82 | { 83 | "aggs": { 84 | "tv_top_price": { 85 | "min": { 86 | "field": "price_gbp" 87 | } 88 | } 89 | } 90 | } 91 | 92 | # Best seller TV (maximum sales) 93 | GET tv_sales/_search 94 | { 95 | "size": 0, 96 | "aggs": { 97 | "tv_sales": { 98 | "max": { 99 | "field": "sales" 100 | } 101 | } 102 | } 103 | } 104 | 105 | # minimum metric What's the lowest price we have in our index? 106 | GET tv_sales/_search 107 | { 108 | "size": 0, 109 | "aggs": { 110 | "lowest_price": { 111 | "min": { 112 | "field": "price_gbp" 113 | } 114 | } 115 | } 116 | } 117 | 118 | #All stats 119 | GET tv_sales/_search 120 | { 121 | "size": 0, 122 | "aggs": { 123 | "all_stats":{ 124 | "stats": { 125 | "field": "price_gbp" 126 | } 127 | } 128 | } 129 | } 130 | 131 | #Extended stats 132 | GET tv_sales/_search 133 | { 134 | "size": 0, 135 | "aggs": { 136 | "extended_stats":{ 137 | "extended_stats": { 138 | "field": "price_gbp" 139 | } 140 | } 141 | } 142 | } 143 | 144 | # Cardinality - unique values of a given field 145 | GET tv_sales/_search 146 | { 147 | "size": 0, 148 | "aggs": { 149 | "unique_tvs": { 150 | "cardinality": { 151 | "field": "brand.keyword" 152 | } 153 | } 154 | } 155 | } 156 | 157 | # BUCKET Aggregations 158 | 159 | ## To index books, copy : https://github.com/madhusudhankonda/elasticsearch-in-action/blob/main/datasets/books.txt 160 | 161 | # Histogram agg 162 | GET books/_search 163 | { 164 | "size": 0, 165 | "aggs": { 166 | "ratings_histogram": { 167 | "histogram": { 168 | "field": "amazon_rating", 169 | "interval": 1 170 | } 171 | } 172 | } 173 | } 174 | 175 | # Histogram on dates - using calendar_interval 176 | GET books/_search 177 | { 178 | "size":0, 179 | "aggs": { 180 | "release_date_histogram": { 181 | "date_histogram": { 182 | "field": "release_date", 183 | "calendar_interval": "year" 184 | } 185 | } 186 | } 187 | } 188 | 189 | # Histogram on with one year interval same as the above 190 | GET books/_search 191 | { 192 | "size":0, 193 | "aggs": { 194 | "release_date_histogram": { 195 | "date_histogram": { 196 | "field": "release_date", 197 | "calendar_interval": "1y" 198 | } 199 | } 200 | } 201 | } 202 | 203 | # ERROR: Histogram on dates - using calendar_interval with 4q (NOT ALLOWED) 204 | GET books/_search 205 | { 206 | "size":0, 207 | "aggs": { 208 | "release_date_histogram": { 209 | "date_histogram": { 210 | "field": "release_date", 211 | "calendar_interval": "4q" 212 | } 213 | } 214 | } 215 | } 216 | 217 | # Histogram on with one a fixed interval of 2 years (730 days) 218 | GET books/_search 219 | { 220 | "size":0, 221 | "aggs": { 222 | "release_date_histogram": { 223 | "date_histogram": { 224 | "field": "release_date", 225 | "fixed_interval": "730d" 226 | } 227 | } 228 | } 229 | } 230 | 231 | # Note the bucket key when using calendar_interval as a year vs fixed_interval as 365d: 232 | 233 | GET books/_search 234 | { 235 | "size":0, 236 | "aggs": { 237 | "release_date_histogram": { 238 | "date_histogram": { 239 | "field": "release_date", 240 | "calendar_interval": "1y" 241 | } 242 | } 243 | } 244 | } 245 | 246 | GET books/_search 247 | { 248 | "size":0, 249 | "aggs": { 250 | "release_date_histogram": { 251 | "date_histogram": { 252 | "field": "release_date", 253 | "fixed_interval": "365d" 254 | } 255 | } 256 | } 257 | } 258 | # Child (nested) data historgram 259 | GET books/_search 260 | { 261 | "size":0, 262 | "aggs": { 263 | "release_date_histogram": { 264 | "date_histogram": { 265 | "field": "release_date", 266 | "calendar_interval": "1y" 267 | }, 268 | "aggs": { 269 | "avg_rating_per_bucket": { 270 | "avg": { 271 | "field": "amazon_rating" 272 | } 273 | } 274 | } 275 | } 276 | } 277 | } 278 | 279 | 280 | # Child (nested) data historgram 281 | GET tv_sales/_search?size=0 282 | { 283 | "aggs": { 284 | "sales_histogram": { 285 | "histogram": { 286 | "field": "sales", 287 | "interval": "10" 288 | }, 289 | "aggs": { 290 | "total_sum": { 291 | "sum": { 292 | "field": "price_gbp" 293 | } 294 | } 295 | } 296 | } 297 | } 298 | } 299 | 300 | ## RANGE aggregation 301 | GET books/_search 302 | { 303 | "size": 0, 304 | "aggs": { 305 | "book_ratings_range": { 306 | "range": { 307 | "field": "amazon_rating", 308 | "ranges": [ 309 | { 310 | "from": 1, 311 | "to": 4 312 | }, 313 | { 314 | "from": 4, 315 | "to": 5 316 | } 317 | 318 | ] 319 | } 320 | } 321 | } 322 | } 323 | 324 | # Terms aggregation 325 | GET books/_search?size=0 326 | { 327 | "aggs": { 328 | "author_book_count": { 329 | "terms": { 330 | "field": "author.keyword" 331 | } 332 | } 333 | } 334 | } 335 | 336 | # Terms aggregation with a custom size 337 | GET books/_search?size=0 338 | { 339 | "aggs": { 340 | "author_book_count": { 341 | "terms": { 342 | "field": "author.keyword", 343 | "size": 25 344 | } 345 | } 346 | } 347 | } 348 | 349 | # Multi-terms: fetching documents with author and title 350 | GET books/_search?size=0 351 | { 352 | "aggs": { 353 | "author_title_map": { 354 | "multi_terms": { 355 | "terms": [ 356 | { 357 | "field": "author.keyword" 358 | }, 359 | { 360 | "field": "title.keyword" 361 | } 362 | ] 363 | } 364 | } 365 | } 366 | } 367 | 368 | #Significant terms: 369 | GET books/_search 370 | GET books/_search?size=0 371 | { 372 | "aggs": { 373 | "NAME": { 374 | "significant_terms": { 375 | "field": "title.keyword" 376 | } 377 | } 378 | } 379 | } 380 | 381 | ## Pipeline Aggregations 382 | 383 | PUT coffee_sales/_doc/1 384 | { 385 | "date":"2022-09-01", 386 | "sales":{ 387 | "cappuccino":23, 388 | "latte":12, 389 | "americano":9, 390 | "tea":7 391 | }, 392 | "price":{ 393 | "cappuccino":2.50, 394 | "latte":2.40, 395 | "americano":2.10, 396 | "tea":1.50 397 | } 398 | } 399 | 400 | PUT coffee_sales/_doc/2 401 | { 402 | "date":"2022-09-02", 403 | "sales":{ 404 | "cappuccino":40, 405 | "latte":16, 406 | "americano":19, 407 | "tea":15 408 | }, 409 | "price":{ 410 | "cappuccino":2.50, 411 | "latte":2.40, 412 | "americano":2.10, 413 | "tea":1.50 414 | } 415 | } 416 | 417 | # Peak time coffee sales 418 | PUT peak_coffee_sales/_doc/1 419 | { 420 | "date":"2022-09-01", 421 | "hour":7, 422 | "sales":{ 423 | "cappuccino":123, 424 | "latte":123, 425 | "americano":95, 426 | "tea":37 427 | } 428 | } 429 | 430 | PUT peak_coffee_sales/_doc/2 431 | { 432 | "date":"2022-09-01", 433 | "hour":8, 434 | "sales":{ 435 | "cappuccino":243, 436 | "latte":428, 437 | "americano":149, 438 | "tea":60 439 | } 440 | } 441 | 442 | PUT peak_coffee_sales/_doc/3 443 | { 444 | "date":"2022-09-01", 445 | "hour":9, 446 | "sales":{ 447 | "cappuccino":199, 448 | "latte":132, 449 | "americano":85, 450 | "tea":34 451 | } 452 | } 453 | 454 | PUT peak_coffee_sales/_doc/1 455 | { 456 | "date":"2022-09-02", 457 | "hour":7, 458 | "sales":{ 459 | "cappuccino":223, 460 | "latte":323, 461 | "americano":195, 462 | "tea":97 463 | } 464 | } 465 | 466 | PUT peak_coffee_sales/_doc/2 467 | { 468 | "date":"2022-09-02", 469 | "hour":8, 470 | "sales":{ 471 | "cappuccino":443, 472 | "latte":628, 473 | "americano":749, 474 | "tea":402 475 | } 476 | } 477 | 478 | PUT peak_coffee_sales/_doc/3 479 | { 480 | "date":"2022-09-02", 481 | "hour":9, 482 | "sales":{ 483 | "cappuccino":328, 484 | "latte":272, 485 | "americano":192, 486 | "tea":93 487 | } 488 | } 489 | 490 | # Coffee sales without a pipeline agg: 491 | GET coffee_sales/_search 492 | { 493 | "size": 0, 494 | "aggs": { 495 | "coffee_sales_by_day": { 496 | "date_histogram": { 497 | "field": "date", 498 | "calendar_interval": "1d" 499 | }, 500 | "aggs": { 501 | "cappucino_sales": { 502 | "sum": { 503 | "field": "sales.cappuccino" 504 | } 505 | } 506 | } 507 | } 508 | } 509 | } 510 | 511 | # Two sigbling aggregations 512 | GET coffee_sales/_search 513 | { 514 | "size": 0, 515 | "aggs": { 516 | "coffee_date_histogram": { 517 | "date_histogram": { 518 | "field": "date", 519 | "calendar_interval": "1d" 520 | } 521 | }, 522 | "total_sale_of_americanos":{ 523 | "sum": { 524 | "field": "sales.americano" 525 | } 526 | } 527 | } 528 | } 529 | 530 | # Two sigbling aggregations 531 | GET coffee_sales/_search 532 | { 533 | "size": 0, 534 | "aggs": { 535 | "coffee_date_histogram": { 536 | "date_histogram": { 537 | "field": "date", 538 | "calendar_interval": "1d" 539 | }, 540 | "aggs": { 541 | "total_sum_americano": { 542 | "sum": { 543 | "field": "price.americano" 544 | } 545 | }, 546 | "cum_sum": { 547 | "cumulative_sum": { 548 | "buckets_path": "total_sum_americano" 549 | } 550 | } 551 | } 552 | }, 553 | "total_sale_of_americanos": { 554 | "sum": { 555 | "field": "sales.americano" 556 | } 557 | } 558 | } 559 | } 560 | 561 | # Cumulative sum of cappuccinos sold 562 | GET coffee_sales/_search 563 | { 564 | "size": 0, 565 | "aggs": { 566 | "sales_by_coffee": { 567 | "date_histogram": { 568 | "field": "date", 569 | "calendar_interval": "1d" 570 | }, 571 | "aggs": { 572 | "cappuccino_sales": { 573 | "sum": { 574 | "field": "sales.cappuccino" 575 | } 576 | }, 577 | "total_cappuccinos": { 578 | "cumulative_sum": { 579 | "buckets_path": "cappuccino_sales" 580 | } 581 | } 582 | } 583 | } 584 | } 585 | } 586 | 587 | # Max sum of cappuccinos sold 588 | GET coffee_sales/_search 589 | { 590 | "size": 0, 591 | "aggs": { 592 | "sales_by_coffee": { 593 | "date_histogram": { 594 | "field": "date", 595 | "calendar_interval": "1d" 596 | }, 597 | "aggs": { 598 | "cappuccino_sales": { 599 | "sum": { 600 | "field": "sales.cappuccino" 601 | } 602 | } 603 | } 604 | }, 605 | "highest_cappuccino_sales_bucket":{ 606 | "max_bucket": { 607 | "buckets_path": "sales_by_coffee>cappuccino_sales" 608 | } 609 | } 610 | } 611 | } 612 | 613 | # Min sum of cappuccinos sold 614 | GET coffee_sales/_search 615 | { 616 | "size": 0, 617 | "aggs": { 618 | "sales_by_coffee": { 619 | "date_histogram": { 620 | "field": "date", 621 | "calendar_interval": "1d" 622 | }, 623 | "aggs": { 624 | "cappucino_sales": { 625 | "sum": { 626 | "field": "sales.cappuccino" 627 | } 628 | } 629 | } 630 | }, 631 | "lowest_cappucino_sales_bucket":{ 632 | "min_bucket": { 633 | "buckets_path": "sales_by_coffee>cappucino_sales" 634 | } 635 | } 636 | } 637 | } 638 | 639 | # Sum of cappuccinos sold 640 | GET coffee_sales/_search 641 | { 642 | "size": 0, 643 | "aggs": { 644 | "sales_by_coffee": { 645 | "date_histogram": { 646 | "field": "date", 647 | "calendar_interval": "1d" 648 | }, 649 | "aggs": { 650 | "cappucino_sales": { 651 | "sum": { 652 | "field": "sales.cappuccino" 653 | } 654 | } 655 | } 656 | }, 657 | "top_bucket":{ 658 | "sum_bucket": { 659 | "buckets_path": "sales_by_coffee>cappucino_sales" 660 | } 661 | } 662 | } 663 | } 664 | -------------------------------------------------------------------------------- /kibana_scripts/ch13_aggregations_index.txt: -------------------------------------------------------------------------------- 1 | PUT mobile_phones 2 | { 3 | "mappings": { 4 | "properties": { 5 | "3G": { 6 | "type": "boolean" 7 | }, 8 | "4G": { 9 | "type": "boolean" 10 | }, 11 | "battery_capacity_mAh": { 12 | "type": "long" 13 | }, 14 | "bluetooth": { 15 | "type": "boolean" 16 | }, 17 | "brand": { 18 | "type": "text", 19 | "fields": { 20 | "keyword": { 21 | "type": "keyword", 22 | "ignore_above": 256 23 | } 24 | } 25 | }, 26 | "front_camera": { 27 | "type": "long" 28 | }, 29 | "gps": { 30 | "type": "boolean" 31 | }, 32 | "id": { 33 | "type": "long" 34 | }, 35 | "internal_storage_GB": { 36 | "type": "integer" 37 | }, 38 | "model": { 39 | "type": "text", 40 | "fields": { 41 | "keyword": { 42 | "type": "keyword", 43 | "ignore_above": 256 44 | } 45 | } 46 | }, 47 | "name": { 48 | "type": "text", 49 | "fields": { 50 | "keyword": { 51 | "type": "keyword", 52 | "ignore_above": 256 53 | } 54 | } 55 | }, 56 | "number_of_sims": { 57 | "type": "byte" 58 | }, 59 | "operating_system": { 60 | "type": "text" 61 | }, 62 | "price_gbp": { 63 | "type": "float" 64 | }, 65 | "price_usd": { 66 | "type": "float" 67 | }, 68 | "processor": { 69 | "type": "byte" 70 | }, 71 | "ram_memory_mb": { 72 | "type": "long" 73 | }, 74 | "rear_camera": { 75 | "type": "long" 76 | }, 77 | "resolution_x": { 78 | "type": "long" 79 | }, 80 | "resolution_y": { 81 | "type": "long" 82 | }, 83 | "screen_size_inches": { 84 | "type": "float" 85 | }, 86 | "touchscreen": { 87 | "type": "boolean" 88 | }, 89 | "wifi": { 90 | "type": "boolean" 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /kibana_scripts/ch14_administration.txt: -------------------------------------------------------------------------------- 1 | # Chapter 14: Adminstration 2 | 3 | PUT chats 4 | { 5 | "settings": { 6 | "number_of_shards": 1, 7 | "number_of_replicas": 1 8 | } 9 | } 10 | 11 | GET _cluster/allocation/explain 12 | { 13 | "index": "chats", 14 | "shard": 0, 15 | "primary": false 16 | } 17 | 18 | GET chats/_settings 19 | 20 | PUT chats/_settings 21 | { 22 | "number_of_replicas": 2 23 | } 24 | 25 | # Register a shanshot - make sure path.repo is set in the elasticsearch.yml file - check Chapter 14 26 | PUT _snapshot/es_cluster_snapshot_repository 27 | { 28 | "type": "fs", 29 | "settings": { 30 | "location": "/volumes/es_snapshots" 31 | } 32 | } 33 | PUT _snapshot/es_cluster_snapshot_repository 34 | { 35 | "type": "fs", 36 | "settings": { 37 | "location": "/tmp/es_snapshots" 38 | } 39 | } 40 | 41 | # Creating a custom snapshot to backup only movies and reviews indices 42 | PUT _snapshot/es_cluster_snapshot_repository/custom_prod_snapshots 43 | { 44 | "indices": ["*movies*","*reviews*"] 45 | } 46 | 47 | # Taking a snapshot with some metadata 48 | PUT _snapshot/es_cluster_snapshot_repository/custom_prod_snapshots_with_metadata 49 | { 50 | "indices": ["*movies*","*reviews*", "-*.old"], 51 | "metadata":{ 52 | "reason":"user request", 53 | "incident_id":"ID12345", 54 | "user":"mkonda" 55 | } 56 | } 57 | 58 | # Fetch snapshot repository 59 | GET _snapshot 60 | 61 | # Get the snapshot status 62 | GET _snapshot/_status 63 | 64 | # GEt the status of the current snapshot 65 | GET _snapshot/es_cluster_snapshot_repository/_current 66 | 67 | # Restoring 68 | 69 | POST _snapshot/es_cluster_snapshot_repository/custom_prod_snapshots/_restore 70 | { 71 | "indices":["*movies*"] 72 | } 73 | 74 | # DELETE a snapshot 75 | 76 | DELETE _snapshot/es_cluster_snapshot_repository/custom_prod_snapshots 77 | 78 | 79 | ## SLM 80 | 81 | # Creating a daily backup on a few indicies 82 | PUT _slm/policy/prod_cluster_daily_backups 83 | { 84 | "name":"", 85 | "schedule": "0 0 0 * * ?", 86 | "repository": "es_cluster_snapshot_repository", 87 | "config": { 88 | "indices":["*movies*", "*reviews*"], 89 | "include_global_state": false, 90 | "ignore_unavailable": false 91 | }, 92 | "retention":{ 93 | "expire_after":"7d" 94 | } 95 | } 96 | 97 | GET _cluster/settings 98 | 99 | PUT _cluster/settings 100 | { 101 | "transient": { 102 | "logger.org.elasticsearch.index":"DEBUG" 103 | } 104 | } 105 | 106 | PUT _cluster/settings 107 | { 108 | "persistent": { 109 | "logger.org.elasticsearch.index":"DEBUG", 110 | "logger.org.elasticsearch.http":"TRACE" 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /kibana_scripts/ch_15_performance_and_trouble_shooting.txt: -------------------------------------------------------------------------------- 1 | # Performance and Troubleshooting 2 | 3 | # Indexing a doc 4 | PUT programming_books1/_doc/1 5 | { 6 | "title":"Elasticsearch in Action", 7 | "synopsis":"A straightforward, hands-on, example driven, action book" 8 | } 9 | # Searching across multiple fields 10 | GET programming_books1/_search 11 | { 12 | "query": { 13 | "multi_match": { 14 | "query": "Elasticsearch hands-on example driven", 15 | "fields": ["title","synopsis"] 16 | } 17 | } 18 | } 19 | 20 | # Index with copy_to field 21 | PUT programming_books2 22 | { 23 | "mappings": { 24 | "properties": { 25 | "title":{ 26 | "type": "text", 27 | "copy_to": "title_synopsis" 28 | }, 29 | "synopsis":{ 30 | "type": "text", 31 | "copy_to": "title_synopsis" 32 | }, 33 | "title_synopsis":{ 34 | "type": "text" 35 | } 36 | } 37 | } 38 | } 39 | 40 | # Indexing a book - only two fields 41 | PUT programming_books2/_doc/1 42 | { 43 | "title":"Elasticsearch in Action", 44 | "synopsis":"A straightforward, hands-on, example driven, action book" 45 | } 46 | 47 | # Match query against the title_synopsis field 48 | GET programming_books2/_search 49 | { 50 | "query": { 51 | "match": { 52 | "title_synopsis": { 53 | "query": "Elasticsearch hands-on example driven", 54 | "operator": "OR" 55 | } 56 | } 57 | } 58 | } 59 | 60 | DELETE programming_books3 61 | # multi-field mapping 62 | PUT programming_books3 63 | { 64 | "mappings": { 65 | "properties": { 66 | "title":{ 67 | "type": "text", 68 | "fields": { 69 | "raw":{ 70 | "type":"keyword" 71 | } 72 | } 73 | } 74 | } 75 | } 76 | } 77 | 78 | # Indexing a document 79 | PUT programming_books3/_doc/1 80 | { 81 | "title":"Elasticsearch in Action" 82 | } 83 | 84 | # Searching on a keyword field 85 | GET programming_books3/_search 86 | { 87 | "query": { 88 | "match": { 89 | "title.raw": "Elasticsearch in Action" 90 | } 91 | } 92 | } 93 | 94 | # Custom refresh setting - 1 min 95 | PUT programming_books3/_settings 96 | { 97 | "index":{ 98 | "refresh_interval":"1m" 99 | } 100 | } 101 | 102 | # Turning off refresh activity completely 103 | PUT programming_books3/_settings 104 | { 105 | "index":{ 106 | "refresh_interval":-1 107 | } 108 | } 109 | 110 | # Index a sample document 111 | PUT programming_books3/_doc/10 112 | { 113 | "title":"Elasticsearch for Java Developers", 114 | "synopsis":"Elasticsearch meets Java" 115 | } 116 | 117 | # If you search for this - you should return no result. 118 | # As we switched off the refresh - it shouldn't be available in search 119 | GET programming_books3/_search 120 | { 121 | "query": { 122 | "match": { 123 | "title": "Elasticsearch Java" 124 | } 125 | } 126 | } 127 | 128 | # Forcing refresh on the index 129 | POST programming_books3/_refresh 130 | 131 | # Fetch the hot threads 132 | GET _nodes/hot_threads 133 | 134 | # Fetch all the thread-pools 135 | GET _nodes/thread_pool 136 | 137 | # Fetch all the thread-pools usign _cat API 138 | GET /_cat/thread_pool/?v&h=name,active,size,type 139 | 140 | GET _cluster/health 141 | 142 | # Allocation API 143 | GET _cluster/allocation/explain 144 | 145 | # Allocation explain API on an individual index 146 | GET _cluster/allocation/explain 147 | { 148 | "index": "programming_books2", 149 | "shard": 0, 150 | "primary": true, 151 | "current_node": "mkmac.local" 152 | } 153 | 154 | # Getting nodes info 155 | 156 | ## Fetch all nodes 157 | GET _nodes 158 | 159 | GET _nodes/process 160 | 161 | GET _cat/nodes?v=true&s=cpu:desc 162 | 163 | # Fetching individual node cpu/memory stats 164 | GET _nodes/stats/os?filter_path=nodes.*.os 165 | 166 | # Watermark thresholds 167 | 168 | ## Chanding the low-watermark 169 | PUT _cluster/settings 170 | { 171 | "transient": { 172 | "cluster.routing.allocation.disk.watermark.low":"80%" 173 | } 174 | } 175 | 176 | ## Chanding the high watermark 177 | PUT _cluster/settings 178 | { 179 | "transient": { 180 | "cluster.routing.allocation.disk.watermark.high":"85%" 181 | } 182 | } 183 | 184 | ## Chanding the flood-stage watermark 185 | PUT _cluster/settings 186 | { 187 | "transient": { 188 | "cluster.routing.allocation.disk.watermark.flood_stage":"90%" 189 | } 190 | } 191 | 192 | # Setting all thresholds in one-go 193 | PUT _cluster/settings 194 | { 195 | "transient": { 196 | "cluster.routing.allocation.disk.watermark.low":"80%", 197 | "cluster.routing.allocation.disk.watermark.high":"85%", 198 | "cluster.routing.allocation.disk.watermark.flood_stage":0.90 199 | } 200 | } 201 | 202 | GET _cluster/settings 203 | 204 | # Fetching circuit breaker settings 205 | GET _nodes/stats/breaker 206 | --------------------------------------------------------------------------------