-
-
Save jnaour/a6bc8056c5f55ef13231 to your computer and use it in GitHub Desktop.
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
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