Last active
December 15, 2015 12:29
-
-
Save katta/5260892 to your computer and use it in GitHub Desktop.
Elastic Search Demo Samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################# | |
### SETUP | |
############################ | |
### Delete all indices | |
curl -XDELETE localhost:9200 | |
### Create an index | |
curl -XPOST localhost:9200/books | |
### Index tw technical books | |
curl -XPOST localhost:9200/books/tw -d' | |
{ | |
"title" : "NoSQL Distilled", | |
"authors" : ["Pramod Sadalge", "Martin Fowler"], | |
"description" : "NoSQL Distilled is a concise but thorough introduction to this rapidly emerging technology. Pramod J. Sadalage and Martin Fowler explain how NoSQL databases work and the ways that they may be a superior alternative to a traditional RDBMS. The authors provide a fast-paced guide to the concepts you need to know in order to evaluate whether NoSQL databases are right for your needs and, if so, which technologies you should explore further.", | |
"tags": ["technical","nosql","sql","database"] | |
}' | |
curl -XGET localhost:9200/books/_mapping | |
curl -XPOST localhost:9200/books/tw -d ' | |
{ | |
"title" : "The Retrospective Handbook", | |
"authors" : ["Patrick Kua"], | |
"description" : "Are you running retrospectives regularly? Perhaps you run retrospectives once a week, or fortnightly. Do you feel like you could be getting more out of your retrospectives and fuelling continuous improvement in your teams? You may already find retrospectives valuable, but suspect there are ways of making them better. This book condenses down eight years of experience working with the retrospective practice within the context of real agile teams.", | |
"price": 9.99, | |
"tags": ["agile","retrospective","process"] | |
}' | |
curl -XGET localhost:9200/books/_mapping | |
### Index comic books | |
curl -XPOST localhost:9200/books/comic -d' | |
{ | |
"title" : "Calvin & Hobbes", | |
"authors" : ["Bill Watterson"], | |
"description" : "A collection of Calvin and Hobbes cartoons. The author won the 1986 Reuben Award as Outstanding Cartoonist of the Year and has also illustrated Something Under the Bed is Drooling , Scientific Progress Goes Boink and Weirdos From Another Planet. Spaceman Spliff, Stupendous Man, the ferocious tiger Hobbes, and the rest of Calvins imaginary friends return in this book. Other books featuring these characters include Something Under the Bed is Drooling, Weirdos from Another Planet and Scientific Progress Goes Boink.", | |
"tags": ["comic"], | |
"isbn" : 9780751516555 | |
}' | |
curl -XGET localhost:9200/books/_mapping | |
################ | |
### Searches | |
################ | |
### Simple Search | |
curl -XGET localhost:9200/books/_search -d' | |
{ | |
"query": { | |
"query_string": { | |
"query": "patrick" | |
} | |
} | |
}' | |
### Highlights Search | |
curl -XGET localhost:9200/books/_search -d' | |
{ | |
"query": { | |
"query_string": { | |
"query": "author" | |
} | |
}, | |
"highlight": { | |
"fields": { | |
"description" : {} | |
} | |
} | |
}' | |
############################# | |
#### REMOVE INDEX SETTINGS ## | |
#### FACET SEARCH ## | |
############################# | |
curl -XDELETE localhost:9200 | |
curl -XPOST localhost:9200/books | |
curl -XPOST localhost:9200/books/tw -d' | |
{ | |
"title" : "NoSQL Distilled", | |
"authors" : ["Pramod Sadalge", "Martin Fowler"], | |
"description" : "NoSQL Distilled is a concise but thorough introduction to this rapidly emerging technology. Pramod J. Sadalage and Martin Fowler explain how NoSQL databases work and the ways that they may be a superior alternative to a traditional RDBMS. The authors provide a fast-paced guide to the concepts you need to know in order to evaluate whether NoSQL databases are right for your needs and, if so, which technologies you should explore further.", | |
"tags": ["technical","nosql","sql","database"] | |
}' | |
curl -XPOST localhost:9200/books/tw -d ' | |
{ | |
"title" : "The Retrospective Handbook", | |
"authors" : ["Patrick Kua"], | |
"description" : "Are you running retrospectives regularly? Perhaps you run retrospectives once a week, or fortnightly. Do you feel like you could be getting more out of your retrospectives and fuelling continuous improvement in your teams? You may already find retrospectives valuable, but suspect there are ways of making them better. This book condenses down eight years of experience working with the retrospective practice within the context of real agile teams.", | |
"price": 9.99, | |
"tags": ["agile","retrospective","process"] | |
}' | |
curl -XPOST localhost:9200/books/comic -d' | |
{ | |
"title" : "Calvin & Hobbes", | |
"authors" : ["Bill Watterson"], | |
"description" : "A collection of Calvin and Hobbes cartoons. The author won the 1986 Reuben Award as Outstanding Cartoonist of the Year and has also illustrated Something Under the Bed is Drooling , Scientific Progress Goes Boink and Weirdos From Another Planet. Spaceman Spliff, Stupendous Man, the ferocious tiger Hobbes, and the rest of Calvins imaginary friends return in this book. Other books featuring these characters include Something Under the Bed is Drooling, Weirdos from Another Planet and Scientific Progress Goes Boink.", | |
"tags": ["comic"], | |
"isbn" : 9780751516555 | |
}' | |
### Facet Search | |
curl -XGET localhost:9200/books/_search -d' | |
{ | |
"query": { | |
"query_string": { | |
"query": "*" | |
} | |
}, | |
"facets": { | |
"tag-category": { | |
"terms": { | |
"field" : "tags" | |
} | |
} | |
} | |
}' | |
############################################### | |
### DELETE ALL INDICES | |
### Phonetic Searches | |
############################################### | |
curl -XPOST 'localhost:9200/books' -d ' | |
{ | |
"settings": { | |
"index": { | |
"analysis": { | |
"analyzer": { | |
"default": { | |
"type": "custom", | |
"tokenizer": "standard", | |
"filter": [ | |
"standard", | |
"lowercase", | |
"my_metaphone" | |
] | |
} | |
}, | |
"filter": { | |
"my_metaphone": { | |
"type": "phonetic", | |
"encoder": "metaphone", | |
"replace": false | |
} | |
} | |
} | |
} | |
} | |
}' | |
curl -XPOST localhost:9200/books/tw -d' | |
{ | |
"title" : "NoSQL Distilled", | |
"authors" : ["Pramod Sadalge", "Martin Fowler"], | |
"description" : "NoSQL Distilled is a concise but thorough introduction to this rapidly emerging technology. Pramod J. Sadalage and Martin Fowler explain how NoSQL databases work and the ways that they may be a superior alternative to a traditional RDBMS. The authors provide a fast-paced guide to the concepts you need to know in order to evaluate whether NoSQL databases are right for your needs and, if so, which technologies you should explore further.", | |
"tags": ["technical","nosql","sql","database"] | |
}' | |
curl -XPOST localhost:9200/books/tw -d ' | |
{ | |
"title" : "The Retrospective Handbook", | |
"authors" : ["Patrick Kua"], | |
"description" : "Are you running retrospectives regularly? Perhaps you run retrospectives once a week, or fortnightly. Do you feel like you could be getting more out of your retrospectives and fuelling continuous improvement in your teams? You may already find retrospectives valuable, but suspect there are ways of making them better. This book condenses down eight years of experience working with the retrospective practice within the context of real agile teams.", | |
"price": 9.99, | |
"tags": ["agile","retrospective","process"] | |
}' | |
curl -XPOST localhost:9200/books/comic -d' | |
{ | |
"title" : "Calvin & Hobbes", | |
"authors" : ["Bill Watterson"], | |
"description" : "A collection of Calvin and Hobbes cartoons. The author won the 1986 Reuben Award as Outstanding Cartoonist of the Year and has also illustrated Something Under the Bed is Drooling , Scientific Progress Goes Boink and Weirdos From Another Planet. Spaceman Spliff, Stupendous Man, the ferocious tiger Hobbes, and the rest of Calvins imaginary friends return in this book. Other books featuring these characters include Something Under the Bed is Drooling, Weirdos from Another Planet and Scientific Progress Goes Boink.", | |
"tags": ["comic"], | |
"isbn" : 9780751516555 | |
}' | |
### Search | |
curl -XGET localhost:9200/books/_search -d' | |
{ | |
"query": { | |
"query_string": { | |
"query": "weak" | |
} | |
} | |
}' | |
##################################### | |
### Shards and Replication | |
### Start atleast three nodes | |
##################################### | |
### Create index with shard settings | |
curl -XPOST 'localhost:9200/books' -d '{ | |
"settings" : { | |
"index" : { | |
"number_of_shards" : 10, | |
"number_of_replicas" : 2 | |
} | |
} | |
}' | |
### index books now | |
curl -XPOST localhost:9200/books/tw -d' | |
{ | |
"title" : "NoSQL Distilled", | |
"authors" : ["Pramod Sadalge", "Martin Fowler"], | |
"description" : "NoSQL Distilled is a concise but thorough introduction to this rapidly emerging technology. Pramod J. Sadalage and Martin Fowler explain how NoSQL databases work and the ways that they may be a superior alternative to a traditional RDBMS. The authors provide a fast-paced guide to the concepts you need to know in order to evaluate whether NoSQL databases are right for your needs and, if so, which technologies you should explore further.", | |
"tags": ["technical","nosql","sql","database"] | |
}' | |
curl -XPOST localhost:9200/books/tw -d ' | |
{ | |
"title" : "The Retrospective Handbook", | |
"authors" : ["Patrick Kua"], | |
"description" : "Are you running retrospectives regularly? Perhaps you run retrospectives once a week, or fortnightly. Do you feel like you could be getting more out of your retrospectives and fuelling continuous improvement in your teams? You may already find retrospectives valuable, but suspect there are ways of making them better. This book condenses down eight years of experience working with the retrospective practice within the context of real agile teams.", | |
"price": 9.99, | |
"tags": ["agile","retrospective","process"] | |
}' | |
curl -XPOST localhost:9200/books/comic -d' | |
{ | |
"title" : "Calvin & Hobbes", | |
"authors" : ["Bill Watterson"], | |
"description" : "A collection of Calvin and Hobbes cartoons. The author won the 1986 Reuben Award as Outstanding Cartoonist of the Year and has also illustrated Something Under the Bed is Drooling , Scientific Progress Goes Boink and Weirdos From Another Planet. Spaceman Spliff, Stupendous Man, the ferocious tiger Hobbes, and the rest of Calvins imaginary friends return in this book. Other books featuring these characters include Something Under the Bed is Drooling, Weirdos from Another Planet and Scientific Progress Goes Boink.", | |
"tags": ["comic"], | |
"isbn" : 9780751516555 | |
}' |
Author
katta
commented
Mar 28, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment