Skip to content

Instantly share code, notes, and snippets.

@radu-gheorghe
radu-gheorghe / sort_array.bash
Created November 7, 2012 11:41
Elasticsearch - sort by the sum of elements within an array
#!/bin/bash
#delete the test type
curl -XDELETE localhost:9200/test/test2/
#insert some docs######
curl -XPOST localhost:9200/test/test2/ -d '{
"id": 123,
"a": 10,
"b": 12,
@radu-gheorghe
radu-gheorghe / id.sh
Created November 9, 2012 20:19
child object ID search
#!/bin/bash
#delete the test index
curl -XDELETE localhost:9200/testing/
echo
#put the document
curl -XPOST localhost:9200/testing/testing/ -d '{
"document": {
"title": "foo",
"id": 1,
@radu-gheorghe
radu-gheorghe / simple_ES_performance
Created November 14, 2012 13:51
simple ES performance test
$ cat inserter.py
import pyes
import sys
conn = pyes.ES('127.0.0.1:9200', bulk_size=int(sys.argv[2]))
for i in range(int(sys.argv[1])):
conn.index({"name":"Joe Tester", "parsedtext":"Joe Testere nice guy", "uuid":"11111", "position":1}, "test-index", "test-type", bulk=True)
$ time python inserter.py 1000 1
@radu-gheorghe
radu-gheorghe / terms_facet.sh
Created November 15, 2012 07:51
Elasticsearch terms facet
curl -XDELETE localhost:9200/test
#{"ok":true,"acknowledged":true}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"red", "counter": 3}'
#{"ok":true,"_index":"test","_type":"test","_id":"MLv-xERyTFaIdkQeaxoiaw","_version":1}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"red", "counter": 7}'
#{"ok":true,"_index":"test","_type":"test","_id":"JaMQIZpbQaKrgdTOtaEEcg","_version":1}
curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"blue", "counter": 5}'
@radu-gheorghe
radu-gheorghe / terms_facet_fail
Created November 15, 2012 07:56
Elasticsearch terms facet string
$ curl -XPOST localhost:9200/test/test/ -d '{"timestamp": "random_date", "tag":"blue", "counter": "5"}'
{"ok":true,"_index":"test","_type":"test","_id":"qVmyc9otSqWqUOKWoteM5Q","_version":1}
$ curl -XGET localhost:9200/test/test/_mapping?pretty=true
{
"test" : {
"properties" : {
"counter" : {
"type" : "string"
},
@radu-gheorghe
radu-gheorghe / es_php_bulk
Created December 4, 2012 14:54
bulk using curl and php
$ cat a.php
<?php
$cmd = "curl -XPUT http://localhost:9200/_bulk --data-binary @bulkIndex.data";
exec($cmd);
?>
$ cat bulkIndex.data
{"index" : {"_index":"test","_type":"mo","_id":"1"} }
{"CDR_ID":"4894","MSISDN":"14169988312","SHORT_CODE":"44446","APP_ID":"1158","OPERATOR_ID":"0","SHORT_MESSAGE":"Test1","SMS_ID":"19f1eb3d1b5579781ba1c051d8d6739e","DATE_TIMESTAMP":"20120727131710","INSERT_TIMESTAMP":"20121129212256"}
{ "index" : {"_index":"test","_type":"mo","_id":"2"} }
{"CDR_ID":"4895","MSISDN":"17059380753","SHORT_CODE":"41128","APP_ID":"1038","OPERATOR_ID":"0","SHORT_MESSAGE":"Test2","SMS_ID":"d8d849f760623f1720ef08634b3867b4","DATE_TIMESTAMP":"20120727131804","INSERT_TIMESTAMP":"20121129212256"}
curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test -d '{
"index.mapper.dynamic": false
}'
#{"ok":true,"acknowledged":true}
curl -XPUT localhost:9200/test/test/1 -d '{"foo":"bar"}'
#{"error":"TypeMissingException[[test] type[test] missing: trying to auto create mapping, but dynamic mapping is disabled]","status":404}
curl -XPUT localhost:9200/testindex/testtype/_mapping -d '{
"testtype": {
"properties":{
"Address": {
"dynamic": true,
"properties": {
"City": {"type": "string", "index": "not_analyzed"}
}
}
}
{
"template_1" : {
"template" : "*",
"access-log" : {
"properties" : {
"@fields": {
"dynamic": "true",
"properties": {
"accessdate" : {
"index" : "not_analyzed",
@radu-gheorghe
radu-gheorghe / child_same_id.sh
Created March 4, 2013 10:44
Elasticsearch: 2 children with the same ID, but with different parents
curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test
curl -XPUT localhost:9200/test/parent/1 -d '{"foo": "p_foo1"}'
curl -XPUT localhost:9200/test/parent/2 -d '{"foo": "p_foo1"}'
curl -XPUT localhost:9200/test/child/_mapping -d '{
"child": {
"_parent": {
"type": "parent"
}
}