Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| courses:cs397:winter2017:elasticsearch [2017/03/27 03:13] – created admin | courses:cs397:winter2017:elasticsearch [2017/04/16 19:26] (current) – [Inserting documents to an index] admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Elasticsearch ====== | ====== Elasticsearch ====== | ||
| + | |||
| + | The following assumes that elasticsearch is running on the localhost on port 9200. | ||
| + | |||
| + | How do I learn more? https:// | ||
| + | |||
| + | ===== General Info about elasticsearch instance ===== | ||
| + | |||
| + | ==== How is elasticsearch doing? ==== | ||
| + | |||
| + | curl -XGET ' | ||
| + | curl -XGET ' | ||
| + | |||
| + | ==== What are the indices on this instance? ==== | ||
| + | |||
| + | curl -XGET ' | ||
| + | |||
| + | ===== Searching Data ===== | ||
| + | |||
| + | |||
| + | ==== Viewing Data ==== | ||
| + | |||
| + | This will give you, by default, the first 20 results as prettified JSON | ||
| + | |||
| + | curl –XGET ‘localhost: | ||
| + | |||
| + | ==== Filtering Results ==== | ||
| + | |||
| + | Only get results that match certain criteria: | ||
| + | |||
| + | curl -XGET ' | ||
| + | |||
| + | |||
| + | curl -XGET ' | ||
| + | " | ||
| + | " | ||
| + | { " | ||
| + | { " | ||
| + | ] | ||
| + | } | ||
| + | } | ||
| + | }' | ||
| + | |||
| + | ==== Sorting Examples ==== | ||
| + | |||
| + | Search '' | ||
| + | |||
| + | curl -XGET ' | ||
| + | |||
| + | Search '' | ||
| + | |||
| + | curl -XGET ' | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | { " | ||
| + | ] | ||
| + | }' | ||
| + | | ||
| + | ==== Limiting Results ==== | ||
| + | |||
| + | Only give one result back from searching '' | ||
| + | |||
| + | curl -XGET ' | ||
| + | | ||
| + | Give back one result, starting at search result 10, from '' | ||
| + | |||
| + | curl -XGET ' | ||
| + | |||
| + | ==== Aggregations ==== | ||
| + | |||
| + | Finding distinct entities | ||
| + | |||
| + | curl -XGET ' | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | }' | ||
| + | |||
| + | ===== Adding Information ===== | ||
| + | |||
| + | ==== Adding an index ==== | ||
| + | |||
| + | curl -XPUT ' | ||
| + | |||
| + | ==== Inserting documents to an index ==== | ||
| + | |||
| + | Insert the JSON document (after the -d) into the index with the id '' | ||
| + | |||
| + | curl –XPUT ‘localhost: | ||
| + | |||
| + | |||
| + | ==== Adding from a File ==== | ||
| + | |||
| + | mongoimport --db dbname --collection whichcollection --file mydata.json | ||
| + | |||
| + | curl -XPOST ' | ||
| + | |||
| + | curl -XPOST ' | ||
| + | ===== Deleting Information ===== | ||
| + | |||
| + | curl -XDELETE ' | ||
