我为了得到哪些值正在使用此查询中有一个字段(SQLfying将是一个SELECT field, count(field) GROUP BY field
ElasticSearch聚集:字符串用空格当作两个字符串
为了做到这一点我。发送该请求,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"]
{
"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是让我的两个值:一个为"living"
,另一个用于"digital"
。我想要使用shole值"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.*
字段。
#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