Skip to content

Instantly share code, notes, and snippets.

@imotov
Created October 31, 2012 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imotov/3990458 to your computer and use it in GitHub Desktop.
Save imotov/3990458 to your computer and use it in GitHub Desktop.
#!/bin/sh
curl -XDELETE localhost:9200/names
curl -XPUT localhost:9200/names -d '{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
},
"mappings" : {
"doc" : {
"properties" : {
"scoreBoosterForSurname" : {"type": "float"}
}
}
}
}'
curl -XPUT localhost:9200/names/doc/1 -d '{
"thisID": "1",
"name": "Elastic",
"surname": "Search",
"scoreBoosterForSurname": "0"
}'
curl -XPUT localhost:9200/names/doc/2 -d '{
"thisID": "2",
"name": "Search",
"surname": "Elastic",
"scoreBoosterForSurname": "10"
}'
curl -XPUT localhost:9200/names/doc/3 -d '{
"thisID": "3",
"name": "Search",
"surname": "Elastic",
"scoreBoosterForSurname": "5"
}'
curl -XPOST localhost:9200/names/_refresh
echo
curl "localhost:9200/names/_search?pretty=true&explain=false" -d '
{
"query": {
"bool": {
"must": [{"query_string": {
"query": "Elastic",
"default_operator": "AND",
"analyze_wildcard": true,
"fields": [
"name",
"surname"
]}}]
}
}
}
'
echo
curl "localhost:9200/names/_search?pretty=true&explain=false" -d '
{
"query": {
"dis_max": {
"queries": [{
"query_string": {
"query": "Elastic",
"default_operator": "AND",
"analyze_wildcard": true,
"default_field": "name"
}
},{
"query_string": {
"query": "Elastic",
"default_operator": "AND",
"analyze_wildcard": true,
"default_field": "surname"
}
}
]
}
}
}
'
echo
curl "localhost:9200/names/_search?pretty=true&explain=false" -d '
{
"query": {
"dis_max": {
"queries": [{
"query_string": {
"query": "Elastic",
"default_operator": "AND",
"analyze_wildcard": true,
"default_field": "name"
}
},{
"custom_score": {
"query": {
"query_string": {
"query": "Elastic",
"default_operator": "AND",
"analyze_wildcard": true,
"default_field": "surname"
}
},
"script" : "_score * doc['\''scoreBoosterForSurname'\''].value"
}
}
]
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment