https://github.com/royrusso/elasticsearch-sample-index
Sample Index script for ElasticSearch. Includes data CSV.
https://github.com/royrusso/elasticsearch-sample-index
Last synced: 12 months ago
JSON representation
Sample Index script for ElasticSearch. Includes data CSV.
- Host: GitHub
- URL: https://github.com/royrusso/elasticsearch-sample-index
- Owner: royrusso
- License: other
- Created: 2013-05-15T03:24:31.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2019-03-11T18:09:11.000Z (over 7 years ago)
- Last Synced: 2023-04-01T07:16:56.130Z (over 3 years ago)
- Language: PHP
- Size: 147 KB
- Stars: 25
- Watchers: 1
- Forks: 16
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
ElasticSearch Sample Index Data Script (PHP)
==========================
This sample script reads from the included CSV file and adds 150 'superhero' documents to an index 'comicbook'.
I needed a way to quickly create indexes/shards and fill them with documents for my [ElasticSearch Monitoring solution](https://github.com/royrusso/elasticsearch-HQ, "Elastic HQ"), and so this project was born.
Usage
--------
* Create the Index:
```
curl -XPUT 'http://localhost:9200/comicbook/' -d '{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 1
}
}
}'
```
* From command line, execute the script:
```
php elasticput.php
```
* Script should output:
```
...
INDEXING ROW: 15 HERO: Punisher
RESPONSE: {"ok":true,"_index":"comicbook","_type":"superhero","_id":"14","_version":1}
INDEXING ROW: 16 HERO: Flash
RESPONSE: {"ok":true,"_index":"comicbook","_type":"superhero","_id":"15","_version":1}
INDEXING ROW: 17 HERO: Magneto
RESPONSE: {"ok":true,"_index":"comicbook","_type":"superhero","_id":"16","_version":1}
...
```
* Once complete, perform a search:
```
http://localhost:9200/comicbook/superhero/_search?q=summary:Kent
hits: {
total: 6,
max_score: 0.71193624,
hits: [
{
_index: "comicbook",
_type: "superhero",
_id: "89",
_score: 0.71193624,
_source: {
name: "Clark Kent",
summary: "Clark Kent is an American fictional character created by Jerry Siegel and Joe Shuster. ..."
}
},
```