が、私はこのクエリを使用しているとして扱う単一のフィールドである(SQLfyingはSELECT field, count(field) GROUP BY field
だろうElasticSearch集約は:スペースを含む文字列値を取得するために、2つの文字列
私はそれを行うために。 ESにこの要求を送信する:このコレクションに一つだけの文書があります
{
"query" : {
"bool" : {
"must" : {
"exists" : {
"field" : "metainfos.ceeaacceaeaaccebeaacceceaaccedeaac"
}
}
}
},
"aggregations" : {
"followUpActivity.metainfo.metainfos.ceeaacceaeaaccebeaacceceaaccedeaac" : {
"terms" : {
"field" : "metainfos.ceeaacceaeaaccebeaacceceaaccedeaac",
"missing" : "null"
}
}
}
}
:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "living_v1",
"_type" : "fuas",
"_id" : "a2cb0ba1-8955-11e6-8a00-0242ac110007",
"_score" : 1.0,
"_routing" : "user2",
"_source" : {
"user" : "user2",
"timestamp" : "2016-10-03T11:08:30.074Z",
"startTimestamp" : "2016-10-03T11:08:30.074Z",
"dueTimestamp" : null,
"closingTimestamp" : null,
"matter" : "Fua 1",
"comment" : null,
"status" : 0,
"backlogStatus" : 20,
"metainfos" : {
"ceeaacceaeaaccebeaacceceaaccedeaac" : [ "Living Digital" ]
},
"resources" : [ ],
"notes" : null
}
} ]
}
}
として、あなたが見ることができるdoc.metainfos.ceeaacc... = ["Living Digital"]
"digital"
のための別の1:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "living_v1",
"_type" : "fuas",
"_id" : "a2cb0ba1-8955-11e6-8a00-0242ac110007",
"_score" : 1.0,
"_routing" : "user2",
"_source":{"user":"user2","timestamp":"2016-10-03T11:08:30.074Z","startTimestamp":"2016-10-03T11:08:30.074Z","dueTimestamp":null,"closingTimestamp":null,"matter":"Fua 1","comment":null,"status":0,"backlogStatus":20,"metainfos":{"ceeaacceaeaaccebeaacceceaaccedeaac":["Living Digital"]},"resources":[],"notes":null}
} ]
},
"aggregations" : {
"followUpActivity.metainfo.metainfos.ceeaacceaeaaccebeaacceceaaccedeaac" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "digital",
"doc_count" : 1
}, {
"key" : "living",
"doc_count" : 1
} ]
}
}
}
ESは私に2つの値を取得しています。ショール値"Living Digital"
を使って集計したいと思います。
マッピングスキームは次のとおりです。
{
"living_v1" : {
"mappings" : {
"fuas" : {
"properties" : {
"backlogStatus" : {
"type" : "long"
},
"comment" : {
"type" : "string"
},
"matter" : {
"type" : "string"
},
"metainfos" : {
"properties" : {
"ceeaacceaeaaccebeaacceceaaccedeaac" : {
"type" : "string"
}
}
},
"startTimestamp" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"status" : {
"type" : "long"
},
"timestamp" : {
"type" : "date",
"format" : "strict_date_optional_time||epoch_millis"
},
"user" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
}
}
あなたが見ることができるように:
"metainfos" : {
"properties" : {
"ceeaacceaeaaccebeaacceceaaccedeaac" : {
"type" : "string"
}
}
}
私にとっての問題は、「ceeaacceaeaaccebeaacceceaaccedeaac」は、ユーザがオンデマンドプロパティを作成し、私にはわからないですどのようにnot-analyzed
をmetainfos.*
フィールドに設定できますか。
EDIT
私がテストしてみた:
#curl -XPUT 'http://localhost:9200/living_v1/' -d '
{
"mappings": {
"fuas": {
"dynamic_templates": [
{
"metainfos": {
"path_match": "metainfos.*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}
'
living_v1
インデックスがすでに存在していることを私に言っています。私の知る限りhereに把握することができました私はPUT
index
に対してを送信する必要があります:あなたはすでに気づいたように、検索行動がデフォルトで適用されたマッピングによって引き起こされる
{
"error":{
"root_cause":[
{
"type":"index_already_exists_exception",
"reason":"already exists",
"index":"living_v1"
}
],
"type":"index_already_exists_exception",
"reason":"already exists",
"index":"living_v1"
},
"status":400
}
ダイナミックインデックステンプレートを探していると思います。http://stackoverflow.com/a/23370138/693546 – mblaettermann