-
-
Save PeteMinus/13617fe53973fed79f64 to your computer and use it in GitHub Desktop.
full elastic 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
POST http://10.10.0.3:9200/companies | |
{ | |
"settings": { | |
"number_of_shards": 1, | |
"number_of_replicas": 1 | |
}, | |
"mappings": { | |
"company": { | |
"properties": { | |
"id": { | |
"type": "string", | |
"store": "true" | |
}, | |
"title": { | |
"type": "string", | |
"store": "true" | |
}, | |
"address_1": { | |
"type": "string", | |
"store": "true" | |
}, | |
"address_2": { | |
"type": "string", | |
"store": "true" | |
}, | |
"address_3": { | |
"type": "string", | |
"store": "true" | |
}, | |
"building_number": { | |
"type": "string", | |
"store": "true" | |
}, | |
"post_code": { | |
"type": "string", | |
"store": "true" | |
}, | |
"language": { | |
"type": "string", | |
"store": "true" | |
}, | |
"rating_value": { | |
"type": "integer", | |
"store": "true" | |
}, | |
"status_live": { | |
"type": "boolean", | |
"store": "true" | |
}, | |
"subscription": { | |
"type": "integer", | |
"store": "true" | |
}, | |
"modified": { | |
"type": "date", | |
"store": "true" | |
}, | |
"location": { | |
"type": "geo_point", | |
"store": "true" | |
}, | |
"county": { | |
"type": "integer", | |
"store": "true" | |
} | |
} | |
}, | |
"employee": { | |
"_parent": { | |
"type": "company" | |
}, | |
"_routing": { | |
"required": true, | |
"path": "company_id" | |
}, | |
"properties": { | |
"id": { | |
"type": "string", | |
"store": "true" | |
}, | |
"company_id": { | |
"type": "string", | |
"store": "true" | |
}, | |
"title": { | |
"type": "string", | |
"store": "true" | |
}, | |
"fname": { | |
"type": "string", | |
"store": "true" | |
}, | |
"lname": { | |
"type": "string", | |
"store": "true" | |
}, | |
"reasons": { | |
"type": "string", | |
"store": "true" | |
} | |
} | |
}, | |
"availability": { | |
"_parent": { | |
"type": "employee" | |
}, | |
"_routing": { | |
"required": true, | |
"path": "company_id" | |
}, | |
"properties" : { | |
"id" : { | |
"type": "string", | |
"store": "true" | |
}, | |
"start" : { | |
"type": "date", | |
"store": "true" | |
}, | |
"duration" : { | |
"type": "string", | |
"store": "true" | |
}, | |
"employee_id" : { | |
"type": "string", | |
"store": "true" | |
}, | |
"company_id" : { | |
"type": "string", | |
"store": "true" | |
} | |
} | |
} | |
} | |
} | |
POST http://10.10.0.3:9200/companies/company/_bulk | |
{ "index": { "_id": "A" }} | |
{"id":"A","title":"Demo A","address_1":"540 Barking Road Plaistow London","address_2":null,"address_3":null,"building_number":null,"post_code":"E13 8QE","language":"en","rating_value":4,"status_live":false,"subscription":5,"location":{"lat":"51.5259028","lon":"0.0292955"},"county":133} | |
{ "index": { "_id": "B" }} | |
{"id":"B","title":"Demo B","address_1":"13 Watson Street Morley Leeds","address_2":null,"address_3":null,"building_number":null,"post_code":"LS27 0AH","language":"en","rating_value":5,"status_live":false,"subscription":5,"location":{"lat":"53.7411803","lon":"-1.6075765"},"county":133} | |
{ "index": { "_id": "C" }} | |
{"id":"C","title":"Demo C","address_1":"2 Green Lane Belper","address_2":null,"address_3":null,"building_number":null,"post_code":"DE56 1BZ","language":"en","rating_value":4,"status_live":false,"subscription":4,"location":{"lat":"53.0234295","lon":"-1.480043"},"county":133} | |
POST http://10.10.0.3:9200/companies/employee/_bulk | |
{"index":{"_id":"A1","parent":"A"}} | |
{"id":"A1","company_id":"A","title":"Employee A1","fname":"Employee","lname":"A1"} | |
{"index":{"_id":"A2","parent":"A"}} | |
{"id":"A2","company_id":"A","title":"Employee A2","fname":"Employee","lname":"A2"} | |
{"index":{"_id":"A3","parent":"A"}} | |
{"id":"A3","company_id":"A","title":"Employee A3","fname":"Employee","lname":"A3"} | |
{"index":{"_id":"A4","parent":"A"}} | |
{"id":"A4","company_id":"A","title":"Employee A4","fname":"Employee","lname":"A4"} | |
{"index":{"_id":"B1","parent":"B"}} | |
{"id":"B1","company_id":"B","title":"Employee B1","fname":"Employee","lname":"B1"} | |
{"index":{"_id":"B2","parent":"B"}} | |
{"id":"B2","company_id":"B","title":"Employee B2","fname":"Employee","lname":"B2"} | |
{"index":{"_id":"B3","parent":"B"}} | |
{"id":"B3","company_id":"B","title":"Employee B3","fname":"Employee","lname":"B3"} | |
{"index":{"_id":"B4","parent":"B"}} | |
{"id":"B4","company_id":"B","title":"Employee B4","fname":"Employee","lname":"B4"} | |
{"index":{"_id":"C1","parent":"C"}} | |
{"id":"C1","company_id":"C","title":"Employee C1","fname":"Employee","lname":"C1"} | |
{"index":{"_id":"C2","parent":"C"}} | |
{"id":"C2","company_id":"C","title":"Employee C2","fname":"Employee","lname":"C2"} | |
{"index":{"_id":"C3","parent":"C"}} | |
{"id":"C3","company_id":"C","title":"Employee C3","fname":"Employee","lname":"C3"} | |
{"index":{"_id":"C4","parent":"C"}} | |
{"id":"C4","company_id":"C","title":"Employee C4","fname":"Employee","lname":"C4"} | |
http://10.10.0.3:9200/companies/availability/_bulk | |
{"index":{"_id":"1","parent":"A1","routing":"A"}} | |
{"id":"1","start":"2015-02-07T14:20:00","duration":"02:10:00","employee_id":"A1","company_id":"A"} | |
{"index":{"_id":"2","parent":"A2","routing":"A"}} | |
{"id":"2","start":"2015-01-07T14:20:00","duration":"02:10:00","employee_id":"A1","company_id":"A"} | |
{"index":{"_id":"3","parent":"A3","routing":"A"}} | |
{"id":"3","start":"2015-01-15T14:20:00","duration":"02:10:00","employee_id":"A3","company_id":"A"} | |
{"index":{"_id":"4","parent":"A4","routing":"A"}} | |
{"id":"4","start":"2015-01-18T14:20:00","duration":"02:10:00","employee_id":"A4","company_id":"A"} | |
{"index":{"_id":"5","parent":"B1","routing":"B"}} | |
{"id":"5","start":"2015-01-10T14:20:00","duration":"02:10:00","employee_id":"B1","company_id":"B"} | |
{"index":{"_id":"6","parent":"B2","routing":"B"}} | |
{"id":"6","start":"2015-01-22T14:20:00","duration":"02:10:00","employee_id":"B2","company_id":"B"} | |
{"index":{"_id":"7","parent":"B3","routing":"B"}} | |
{"id":"7","start":"2015-01-22T14:20:00","duration":"02:10:00","employee_id":"B3","company_id":"B"} | |
{"index":{"_id":"8","parent":"B4","routing":"B"}} | |
{"id":"8","start":"2015-01-23T14:20:00","duration":"02:10:00","employee_id":"B4","company_id":"B"} | |
{"index":{"_id":"9","parent":"C1","routing":"C"}} | |
{"id":"9","start":"2015-01-11T14:20:00","duration":"02:10:00","employee_id":"C1","company_id":"C"} | |
{"index":{"_id":"10","parent":"C2","routing":"C"}} | |
{"id":"10","start":"2015-01-12T14:20:00","duration":"02:10:00","employee_id":"C2","company_id":"C"} | |
{"index":{"_id":"11","parent":"C3","routing":"C"}} | |
{"id":"11","start":"2015-01-17T14:20:00","duration":"02:10:00","employee_id":"C3","company_id":"C"} | |
{"index":{"_id":"12","parent":"C4","routing":"C"}} | |
{"id":"12","start":"2015-01-20T14:20:00","duration":"02:10:00","employee_id":"C4","company_id":"C"} | |
http://10.10.0.3:9200/companies/company/_search | |
{ | |
"query": { | |
"filtered": { | |
"filter": { | |
"and": [ | |
{ | |
"term": { | |
"county": "133" | |
} | |
}, | |
{ | |
"term": { | |
"language": "en" | |
} | |
}, | |
{ | |
"has_child": { | |
"type": "employee", | |
"query": { | |
"filtered": { | |
"filter": { | |
"and": [ | |
{ | |
"has_child": { | |
"type": "availability", | |
"query": { | |
"filtered": { | |
"filter": { | |
"and": [ | |
{ | |
"range": { | |
"start": { | |
"gt": "2014-12-22T10:34:18+01:00" | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
] | |
}, | |
"query": [ | |
] | |
} | |
}, | |
"script_fields": { | |
"distance": { | |
"params": { | |
"lat": 51.5186, | |
"lon": -0.1347 | |
}, | |
"script": "doc[\\u0027location\\u0027].distanceInMiles(lat,lon)" | |
} | |
}, | |
"aggs": { | |
"practice_agg": { | |
"terms": { | |
"field": "id", | |
"size": 10 | |
}, | |
"aggs": { | |
"employee_agg": { | |
"children": { | |
"type": "employee" | |
}, | |
"aggs": { | |
"employee_id": { | |
"terms": { | |
"field": "id", | |
"size": 10 | |
}, | |
"aggs": { | |
"availability_agg": { | |
"children": { | |
"type": "availability" | |
}, | |
"aggs": { | |
"availability": { | |
"stats": { | |
"field": "company.employee.availability.employee_id" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"fields": [ | |
"*", | |
"distance" | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pete, you still working this problem? Your SO post was 7 months back.