Created
June 19, 2013 11:13
-
-
Save anonymous/5813541 to your computer and use it in GitHub Desktop.
elasticsearch example
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
#! /bin/bash | |
#DELETE | |
curl -XDELETE 'http://localhost:9200/test' | |
echo | |
# DEFINE | |
curl -XPUT 'http://localhost:9200/test/posts/_mapping?pretty=1' -d '{ | |
"posts" : { | |
"properties" : { | |
"section" : { | |
"type" : "string", | |
"similarity" : "BM25" | |
}, | |
"category" : { | |
"type" : "string", | |
"similarity" : "BM25" | |
}, | |
"title" : { | |
"type" : "string", | |
"similarity" : "BM25" | |
} | |
} | |
} | |
}' | |
echo | |
# INSERT | |
curl localhost:9200/test/posts/1 -d '{section: "Bicycle", category: "Small", title: "Diamondback Grind-16"}' | |
curl localhost:9200/test/posts/2 -d '{section: "Bicycle", category: "Big", title: "Diamondback JrViper"}' | |
curl localhost:9200/test/posts/3 -d '{section: "Bicycle", category: "Small", title: "2-Hip Cyclone Small"}' | |
curl localhost:9200/test/posts/4 -d '{section: "Bicycle", category: "Big", title: "2-Hip Bizzle"}' | |
curl localhost:9200/test/posts/5 -d '{section: "Small", category: "Small", title: "Toyota"}' | |
curl localhost:9200/test/posts/6 -d '{section: "Car", category: "Big", title: "Subaru Impreza Small"}' | |
curl localhost:9200/test/posts/7 -d '{section: "Small", category: "Big", title: "Toyota Corona MARK II"}' | |
curl localhost:9200/test/posts/8 -d '{section: "Car", category: "Small", title: "Hyundai Elantra"}' | |
curl localhost:9200/test/posts/9 -d '{section: "Car", category: "Big", title: "Ford Maverick small"}' | |
echo | |
# REFRESH | |
curl -XPOST localhost:9200/test/_refresh | |
echo | |
# SEARCH | |
curl "localhost:9200/test/posts/_search?pretty=1" -d '{ | |
"query" : { | |
"bool": { | |
"must": [ | |
{ | |
"multi_match": { | |
"query": "small", | |
"fields": ["section^30", "category^10", "title"], | |
"use_dis_max": "false" | |
} | |
} | |
] | |
} | |
}, | |
"explain": "true" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment