Created
May 13, 2014 04:01
-
-
Save dqduc/efa66047358dac66461b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XDELETE 'http://localhost:9200/test' | |
curl -XPOST 'http://localhost:9200/test' -d '{ | |
"settings" : { | |
"number_of_shards" : 1, | |
"number_of_replicas" : 0 | |
}, | |
"mappings" : { | |
"article" : { | |
"properties" : { | |
"title": { "type": "string", "analyzer": "standard" }, | |
"id": { "type": "string", "index": "not_analyzed" } | |
} | |
}, | |
"comment" : { | |
"_parent" : { | |
"type" : "article" | |
}, | |
"properties" : { | |
"body": { "type": "string", "analyzer": "standard" }, | |
"commentof": { "type": "string", "index": "not_analyzed" } | |
} | |
} | |
} | |
}' | |
// data for parent | |
curl -XPUT 'http://localhost:9200/test/article/myArticle1' -d '{ | |
"title": "something about brown food", | |
"id": "myArticle1" | |
}' | |
curl -XPUT 'http://localhost:9200/test/article/2' -d '{ | |
"title": "other stuff", | |
"id": "2" | |
}' | |
//data for child | |
curl -XPUT 'http://localhost:9200/test/comment/1?parent=myArticle1' -d '{ | |
"body": "I love chocolates!" | |
}' | |
curl -XPUT 'http://localhost:9200/test/comment/2?parent=myArticle1' -d '{ | |
"body": "me too" | |
}' | |
curl -XPUT 'http://localhost:9200/test/comment/4?parent=2' -d '{ | |
"body": "I love orange!" | |
}' | |
curl -XPOST 'http://localhost:9200/test/_refresh' | |
echo | |
echo 'Searching for [chocolates]' | |
curl 'http://localhost:9200/test/article/_search' -d '{ | |
"query": { | |
"has_child": { | |
"type": "comment", | |
"query": { | |
"query_string": { | |
"default_field" : "body", | |
"query" : "chocolates" | |
} | |
} | |
} | |
} | |
}' | |
echo | |
echo 'Searching for [orange]' | |
curl 'http://localhost:9200/test/article/_search' -d '{ | |
"query": { | |
"has_child": { | |
"type": "comment", | |
"query": { | |
"query_string": { | |
"default_field" : "body", | |
"query" : "orange" | |
} | |
} | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment