21 handy elasticsearch queries
Elasticsearch is a powerful, fast and surprisingly user freindly data store and search tool. It’s not quite a database and it’s not quite a search engine, elasticsearch sits somewhere comfortably in between.
For these examples, we’ll store some domain names, Ip addresses and related information as that is a lot more fun than traditional bookstore type demos and example apps.
First, we’ll create the index:
1 2 |
PUT /domaindb_index { "settings": { "number_of_shards": 1 }} |
That will create a basic index with a single shard called “domaindb”
1 2 3 4 5 6 7 8 9 10 11 12 13 |
POST /domaindb_index/domain/_bulk { "index": { "_id": 1 }} { "title": "google.com", "ip": ["216.58.193.78"], "description" : "Words most popular search engine", "updated_date" : "2015-02-07"} { "index": { "_id": 2 }} { "title": "yahoo.com", "ip": ["206.190.36.45"], "description", "Search, news, email provider"], "updated_date" : "2013-01-24"} { "index": { "_id": 3 }} { "title": "bing.com", "ip": ["13.107.21.200"], "description", "updated_date" : "2014-01-24"} |
1 2 3 |
{ "index": { "_id": 3 }} { "title": "bing.com", "ip": ["13.107.21.200", "description", "Search, news, email provider"], "updated_date" : "2013-01-24"} |
Now that we’ve got a basic index with some data, let’s try a first query. We’ll search for “google” within every field in the entire index.
1 |
Now that we've got a basic index with some data, let's try a first query. We'll search for "google" within every field in the entire index. |
1 |
GET /domaindb_index/book/_search?q=google |