Skip to content

Instantly share code, notes, and snippets.

@jprante
Created October 16, 2013 08:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jprante/7004392 to your computer and use it in GitHub Desktop.
Identifier-based relationships in Elasticsearch
# Demo for identifier-based relationships (in a single index)
curl -XDELETE 'localhost:9200/test'
curl -XPUT 'localhost:9200/test/person/d63593854658686406da5ea87c346d55' -d '
{
"name" : "Cutting",
"firstname" : "Doug"
}
'
curl -XPUT 'localhost:9200/test/person/0a16691adcb5187ddfd1d3db2ca52b5b' -d '
{
"name" : "Banon",
"firstname" : "Shay"
}
'
curl -XPUT 'localhost:9200/test/person/539105ce53335061ef0467bd3915dd32' -d '
{
"name" : "Willnauer",
"firstname" : "Simon"
}
'
curl -XPUT 'localhost:9200/test/software/s1' -d '
{
"title" : "Lucene",
"content" : "Apache Lucene is a high-performance, full-featured text search engine library written entirely in Java"
}
'
curl -XPUT 'localhost:9200/test/software/s2' -d '
{
"title" : "Elasticsearch",
"content" : "Elasticsearch is a powerful open source search and analytics engine that makes data easy to explore"
}
'
curl -XPUT 'localhost:9200/test/relations/s1' -d '
{
"author" : [
"d63593854658686406da5ea87c346d55"
],
"contributor" : [
"d63593854658686406da5ea87c346d55",
"539105ce53335061ef0467bd3915dd32"
]
}
'
curl -XPUT 'localhost:9200/test/relations/s2' -d '
{
"author" : [
"0a16691adcb5187ddfd1d3db2ca52b5b"
],
"contributor" : [
"0a16691adcb5187ddfd1d3db2ca52b5b",
"539105ce53335061ef0467bd3915dd32"
]
}
'
curl -XGET 'localhost:9200/test/_refresh'
echo
echo "searching for hits in software"
curl -XGET 'localhost:9200/test/software/_search?pretty' -d '
{
"query" : {
"query_string": {
"query": "search"
}
}
}'
echo
echo "obtain relations of the hits, building unique list of authors and contributors per hit"
curl -XGET 'localhost:9200/test/relations/_mget' -d '
{
"docs" : [ { "_id" : "s1" }, { "_id" : "s2" } ]
}
'
echo
echo "obtain person info of s1 authors"
curl -XGET 'localhost:9200/test/person/_mget' -d '
{
"docs" : [ { "_id" : "d63593854658686406da5ea87c346d55" } ]
}'
echo
echo "obtain person info of s1 contributors (except s1 authors)"
curl -XGET 'localhost:9200/test/person/_mget' -d '
{
"docs" : [ { "_id" : "0a16691adcb5187ddfd1d3db2ca52b5b" } ]
}'
echo
echo "obtain person info of s2 authors"
curl -XGET 'localhost:9200/test/person/_mget' -d '
{
"docs" : [ { "_id" : "0a16691adcb5187ddfd1d3db2ca52b5b" } ]
}'
echo
echo "obtain person info of s2 contributors (except s2 authors)"
curl -XGET 'localhost:9200/test/person/_mget' -d '
{
"docs" : [ { "_id" : "539105ce53335061ef0467bd3915dd32" } ]
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment