Skip to content

Instantly share code, notes, and snippets.

@jnaour

jnaour/example Secret

Last active December 20, 2015 12:29
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 jnaour/a6bc8056c5f55ef13231 to your computer and use it in GitHub Desktop.
Save jnaour/a6bc8056c5f55ef13231 to your computer and use it in GitHub Desktop.
curl -XPUT 'localhost:9200/example' -d '
{
"mappings":{
"nestedTravels":{
"_source":{
"enabled":"true"
},
"properties":{
"TravelsByHour":{
"type":"nested",
"properties":{
"state":{
"type":"string"
},
"count":{
"type":"integer"
}
}
},
"CI":{
"properties":{
"CIStation":{
"type":"string"
},
"CIName":{
"type":"string"
},
"CIGeo":{
"type":"geo_point"
}
}
},
"CO":{
"properties":{
"COStation":{
"type":"string"
},
"COName":{
"type":"string"
},
"COGeo":{
"type":"geo_point"
}
}
},
"TravelDate":{
"type":"date",
"format":"yyyy-MM-dd"
},
"CIMode":{
"type":"string"
}
}
}
}
}
'
curl -XPUT 'localhost:9200/example/nestedTravels/123' -d '
{
"TravelsByHour":[{
"state":"05",
"count":54
},{
"state":"06",
"count":1
},{
"state":"07",
"count":1
},{
"state":"16",
"count":6
},{
"state":"20",
"count":1
},{
"state":"23",
"count":8
}],
"CI":{
"CIStation":"10",
"CIName":"Station 1",
"CIGeo":{
"lat":80.50,
"lon":80.50
}
},
"CO":{
"COStation":"39",
"COName":"Station 2",
"COGeo":{
"lat":80.50,
"lon":80.51
}
},
"TravelDate":"2013-06-27",
"CIMode":"Train"
}
'
curl -XPUT 'localhost:9200/example/nestedTravels/456' -d '
{
"TravelsByHour":[{
"state":"01",
"count":10
},{
"state":"07",
"count":12
},{
"state":"16",
"count":5
},{
"state":"29",
"count":1
},{
"state":"23",
"count":9
}],
"CI":{
"CIStation":"10",
"CIName":"Station 1",
"CIGeo":{
"lat":80.50,
"lon":80.50
}
},
"CO":{
"COStation":"39",
"COName":"Station 2",
"COGeo":{
"lat":80.50,
"lon":80.51
}
},
"TravelDate":"2013-06-28",
"CIMode":"Train"
}
'
# terms stats facets, the result is close from what I want
curl -XPOST 'localhost:9200/example/_search?pretty=true' -d '
{
"facets": {
"myFacet": {
"terms_stats": {
"key_field": "TravelsByHour.state",
"value_field": "TravelsByHour.count"
},
"nested": "TravelsByHour"
}
}
}
'
# There is an error here: nested: ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData cannot be cast to org.elasticsearch.index.fielddata.IndexNumericFieldData]
curl -XPOST 'localhost:9200/example/_search?pretty=true' -d '
{
"facets": {
"myFacet": {
"histogram": {
"key_field": "TravelsByHour.state",
"value_field": "TravelsByHour.count",
"interval": 100
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment