Skip to content

Instantly share code, notes, and snippets.

@lukas-vlcek
Created September 17, 2012 20:07
Show Gist options
  • Save lukas-vlcek/3739469 to your computer and use it in GitHub Desktop.
Save lukas-vlcek/3739469 to your computer and use it in GitHub Desktop.
#!/bin/sh
echo "\n --- delete index"
curl -X DELETE 'http://localhost:9200/'
echo "\n --- create index and put mapping into place"
curl -X POST 'http://localhost:9200/myindex/' -d '{
"mappings" : {
"person" : {
"properties" : {
"name" : {"type" : "string"},
"works" : {
"type" : "nested",
"include_in_parent" : false,
"properties" : {
"title" : {"type" : "string"},
"current" : {"type" : "boolean"},
"dummy" : {"type" : "string"}
}
}
}
}
},
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}'
echo "\n --- index data"
curl -X PUT 'http://localhost:9200/myindex/person/1' -d '
{
"name" : "Lukas",
"works" : [
{
"title" : "developer",
"current" : true,
"dummy" : "match"
},
{
"title" : "dad",
"current" : true
},
{
"title" : "husband",
"current" : true,
"dummy" : "foo"
},
{
"title" : "brother",
"current" : true,
"dummy" : "bar"
}
]
}'
curl -X PUT 'http://localhost:9200/myindex/person/2' -d '
{
"name" : "Karel",
"works" : [
{
"title" : "developer",
"current" : true,
"dummy" : "match"
}
]
}'
curl -X PUT 'http://localhost:9200/myindex/person/3' -d '
{
"name" : "Jan",
"works" : [
{
"title" : "developer",
"current" : false,
"dummy" : "match"
}
]
}'
echo "\n --- optimize"
curl -X POST 'http://localhost:9200/_optimize'
#!/bin/sh
echo "\n --- query"
curl -X GET 'http://localhost:9200/_search?pretty=true' -d '
{
"query" : {
"nested" : {
"path" : "works",
"query" : {
"bool" : {
"must" : [
{ "text" : { "works.dummy" : "match"} }
],
"should" : [
{ "text" : { "works.title" : "developer"} },
{ "text" : { "works.current" : true } }
]
}
}
}
},
"fields" : [
"name"
]
}'
echo "\n --- done"
# ===========================================
# Output
# ===========================================
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 2.9213471,
"hits" : [ {
"_index" : "myindex",
"_type" : "person",
"_id" : "1",
"_score" : 2.9213471,
"fields" : {
"name" : "Lukas"
}
}, {
"_index" : "myindex",
"_type" : "person",
"_id" : "2",
"_score" : 2.9213471,
"fields" : {
"name" : "Karel"
}
}, {
"_index" : "myindex",
"_type" : "person",
"_id" : "3",
"_score" : 1.4967837,
"fields" : {
"name" : "Jan"
}
} ]
}
}
@eamocanu
Copy link

@ungureanuliviu have you figured it out? I'm looking for the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment