Skip to content

Instantly share code, notes, and snippets.

@sarathrs
Created January 5, 2016 08:02
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 sarathrs/027a23da49a67c1ada2f to your computer and use it in GitHub Desktop.
Save sarathrs/027a23da49a67c1ada2f to your computer and use it in GitHub Desktop.
#Mapping
PUT /company
{
"mappings": {
"branch": {
"_id": {
"path": "id"
},
"properties" : {
"location" : {
"type" : "geo_point"
}
}
},
"employee": {
"_parent": {
"type": "branch"
},
"_id": {
"path": "id"
}
}
}
}
#ElasticSearch Query
{
"query": {
"bool": {
"must": [
{
"function_score": {
"query": {
"bool": {
"should": {
"has_child": {
"query": {
"term": {
"name": "test"
}
},
"child_type": "employee",
"score_type": "sum",
"_name": "fs.child.query"
}
}
}
},
"functions": [
{
"filter": {
"has_child": {
"filter": {
"term": {
"name": "test"
}
},
"child_type": "employee",
"_name": "fs.child.filter"
}
},
"script_score": {
"script": "1",
"lang": "mvel"
}
}
],
"score_mode": "sum",
"boost_mode": "replace"
}
}
],
"should": [
{
"dis_max": {
"tie_breaker": 0.05,
"_name": "match.location.subclause",
"queries": [
{
"bool": {
"should": {
"function_score": {
"query": {
"constant_score": {
"filter": {
"geo_distance": {
"location": [
-71.41617,
41.7001
],
"distance": "10.0km"
}
}
}
},
"functions": [
{
"exp": {
"location": {
"origin": "41.7001,-71.41617",
"scale": "10.0km"
}
}
},
{
"script_score": {
"script": "_score * 3.5",
"lang": "mvel"
}
}
],
"score_mode": "multiply"
}
},
"_name": "location.clause"
}
}
]
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment