Skip to content

Instantly share code, notes, and snippets.

@johtani
Created November 18, 2013 03:16
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 johtani/7521874 to your computer and use it in GitHub Desktop.
Save johtani/7521874 to your computer and use it in GitHub Desktop.
Mappingでdoubleを指定して、文字列で数値データ登録してみたらどうなるか。 ※0.90.7で実験
# index作成
curl -XPUT localhost:9200/hoge
# mappingの指定
curl -XPUT localhost:9200/hoge/fuga/_mapping -d '{
"fuga" : {
"numeric_detection" : false,
"properties" : {
"Resp_Time" : {"type" : "double"}
}
}
}'
# データ登録(文字列?)
curl -XPUT localhost:9200/hoge/fuga/1 -d '{"Resp_Time" : "12.09" }'
curl -XPUT localhost:9200/hoge/fuga/2 -d '{"Resp_Time" : "12.11" }'
# 検索実施(statistical facetを利用:数値or日付データしか計算出来ない。http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-statistical-facet.html)
curl -XPOST "http://localhost:9200/fuga/fuga/_search?pretty" -d'
> {
> "query" : {
> "match_all": {}
> },
> "facets" : {
> "stat1" : {
> "statistical" : {
> "field" : "Resp_Time"
> }
> }
> }
> }'
# 結果
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "fuga",
"_type" : "fuga",
"_id" : "2",
"_score" : 1.0, "_source" : {
"Resp_Time" : "12.11" }
}, {
"_index" : "fuga",
"_type" : "fuga",
"_id" : "1",
"_score" : 1.0, "_source" : {
"Resp_Time" : "12.09" }
} ]
},
"facets" : {
"stat1" : {
"_type" : "statistical",
"count" : 2,
"total" : 24.2,
"min" : 12.09,
"max" : 12.11,
"mean" : 12.1,
"sum_of_squares" : 292.8202,
"variance" : 1.0000000000331966E-4,
"std_deviation" : 0.010000000000165982
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment