Skip to content

Instantly share code, notes, and snippets.

@imotov
Last active November 16, 2022 01:30
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/5241590 to your computer and use it in GitHub Desktop.
Save imotov/5241590 to your computer and use it in GitHub Desktop.
curl -XDELETE localhost:9200/test
curl -XPUT localhost:9200/test -d '{
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 0
}
}
'
curl -XPOST localhost:9200/test/doc/1 -d '{
"dna":[
{
"color":2397879,
"area":0.4
},
{
"color":938893,
"area":0.3
},
{
"color":3498438,
"area":0.2
},
{
"color":894879,
"area":0.1
}
]
}
'
curl -X POST 'http://localhost:9200/test/_refresh'
curl -X GET 'http://localhost:9200/test/doc/_search?pretty' -d '{
"query": {
"filtered" : {
"query": {
"match_all": {}
},
"filter": {
"range" : {
"dna.color": {
"from": 900000,
"to": 1100000
}
}
}
}
},
"sort": {
"_script": {
"script": "area = 0; mindiff = Long.MAX_VALUE; for (entry : _source.dna) {diff = Math.abs(entry.color - target); if (diff < mindiff) { mindiff = diff; area = entry.area } }; mindiff * area",
"type": "number",
"params": {
"target" : 1000000
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment