Skip to content

Instantly share code, notes, and snippets.

@radu-gheorghe
radu-gheorghe / count_children.sh
Created November 28, 2012 17:58
Query parents and count children
#cleanup first
curl -XDELETE localhost:9200/test/
echo
#create index
curl -XPUT localhost:9200/test
echo
#create parent type
curl -XPUT localhost:9200/test/test_parent
@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"
}
}
@radu-gheorghe
radu-gheorghe / parent_child_ttl.sh
Created March 8, 2013 15:04
different TTL for parents and children test. Assumes: $ tail -1 /etc/elasticsearch/elasticsearch.yml indices.ttl.interval: 1s
curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test
curl -XPUT localhost:9200/test/p/_mapping -d '{
"p" :{
"_ttl" : { "enabled" : true, "default": "10s" }
}
}'
curl -XPUT localhost:9200/test/c/_mapping -d '{
"c" :{
"_ttl" : { "enabled" : true, "default": "20s" }
@radu-gheorghe
radu-gheorghe / includes_excludes.sh
Created March 28, 2013 18:08
Test for includes and excludes options of _source
curl -XDELETE localhost:9200/test1/
curl -XDELETE localhost:9200/test2/
curl -XPUT localhost:9200/test1/
curl -XPUT localhost:9200/test1/source_includes/_mapping -d '{
"source_includes": {
"_source": {
"includes": [ "included" ]
}
}
}'
@radu-gheorghe
radu-gheorghe / multiple_child_levels.bash
Created April 23, 2013 09:04
multiple parent-child level query with Elasticsearch
curl -XDELETE localhost:9200/test/
curl -XPUT localhost:9200/test/
curl -XPUT localhost:9200/test/son/_mapping -d '{
"son": {
"_parent": {
"type": "mother"
}
}
}'
curl -XPUT localhost:9200/test/daughter/_mapping -d '{
@radu-gheorghe
radu-gheorghe / track_scores.bash
Created April 28, 2013 09:00
Elasticsearch should still show scores for each hit when sorting on a field and track_scores is true
curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test/test/1 -d '{"foo": "bar"}'
curl -XPOST localhost:9200/test/_refresh
echo
echo "==============="
echo -e "\e[00;32mCORRECT: SCORE IS SHOWN WHEN SORTING ON SCORE\e[00m"
echo "==============="
curl 'localhost:9200/test/test/_search?q=bar&pretty' 2>/dev/null | grep score
echo
echo "==============="