Skip to content

Instantly share code, notes, and snippets.

@nespera
Last active May 23, 2016 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nespera/af5c30a82a50f266870b53d1fb46874a to your computer and use it in GitHub Desktop.
Save nespera/af5c30a82a50f266870b53d1fb46874a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
curl -X DELETE "http://localhost:9200/nestedscoring"
echo
echo
curl -X PUT -H "Content-type:text/json" -d@- "http://localhost:9200/nestedscoring" << EOF
{
"mappings": {
"document": {
"properties": {
"tag": {
"type": "nested",
"properties": {
"text": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
EOF
echo
echo
curl -X PUT -H "Content-type:text/json" -d@- "http://localhost:9200/nestedscoring/document/1" << EOF
{
"tag": [
{
"text" : "aaaa"
}
]
}
EOF
echo
echo
curl -X PUT -H "Content-type:text/json" -d@- "http://localhost:9200/nestedscoring/document/2" << EOF
{
"tag": [
{
"text" : "bbbb"
}
]
}
EOF
echo
echo
curl -X PUT -H "Content-type:text/json" -d@- "http://localhost:9200/nestedscoring/document/3" << EOF
{
"tag": [
{
"text" : "cccc"
}
]
}
EOF
echo
echo
curl -X PUT -H "Content-type:text/json" -d@- "http://localhost:9200/nestedscoring/document/4" << EOF
{
"tag": [
{
"text" : "dddd"
}
]
}
EOF
echo
echo
sleep 2
curl -X POST -H "Content-type:text/json" -d@- "http://localhost:9200/nestedscoring/_search?pretty=true" << EOF
{
"query": {
"nested": {
"path": "tag",
"score_mode": "sum",
"query": {
"bool": {
"should": [
{
"term": {
"tag.text": {
"value": "bbbb"
}
}
},
{
"term": {
"tag.text": {
"value": "aaaa"
}
}
}
]
}
}
}
}
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment