我正在嘗試編寫一個將所有博客分組到同一個博客域(elasticpress.com,blog.com等)的elasticsearch查詢。這是我的查詢看起來像:ElasticSearch:URL的聚合不斷分裂字段
{
"engagements": [
"blogs"
],
"query": {
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"range": {
"weight": {
"gte": 120,
"lte": 150
}
}
}
]
}
}
}
},
"facets": {
"my_facet": {
"terms": {
"field": "blog_domain" <-------------------------------------
}
}
}
},
"api": "_search"
}
然而,它的返回這樣的:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
...
]
},
"facets": {
"my_facet": {
"_type": "terms",
"missing": 0,
"total": 21,
"other": 3,
"terms": [
{
"term": "http",
"count": 3
},
{
"term": "noblepig.com",
"count": 2
},
{
"term": "hawaiian",
"count": 2
},
{
"term": "dream",
"count": 2
},
{
"term": "dessert",
"count": 2
},
{
"term": "2015",
"count": 2
},
{
"term": "05",
"count": 2
},
{
"term": "www.bt",
"count": 1
},
{
"term": "photos",
"count": 1
},
{
"term": "images.net",
"count": 1
}
]
}
}
}
這不是我想要的。 現在我的數據庫中有三個記錄:
"http://www.bt-images.net/8-cute-photos-cats/",
"http://noblepig.com/2015/05/hawaiian-dream-dessert/",
"http://noblepig.com/2015/05/hawaiian-dream-dessert/"
我希望它返回類似:
"facets": {
"my_facet": {
"_type": "terms",
"missing": 0,
"total": 21,
"other": 3,
"terms": [
{
"term": "http://noblepig.com/2015/05/hawaiian-dream-dessert/",
"count": 2
},
{
"term": "http://www.bt-images.net/8-cute-photos-cats/",
"count": 1
},
我會怎麼做呢?我查了一下,看到有人推薦mappings
,但我不知道該查詢的位置,我的表有1億條記錄,所以現在做得太遲了。如果您有建議,可否請粘貼整個查詢?
{
"engagements": [
"blogs"
],
"query": {
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"range": {
"weight": {
"gte": 13,
"lte": 75
}
}
}
]
}
}
}
},
"aggs": {
"blah": {
"terms": {
"field": "blog_domain"
}
}
}
},
"api": "_search"
}
我進一步挖掘,最終發現,我有一個'not_analyzed'指數...還我說錯,這個表是新的,只有映射3條記錄,所以我可以自由切換。這些記錄是否可能在索引出現之前創建? – Edmund
字段是'not_analyzed',而不是索引。文件不能存在於索引之外。我認爲你在混淆事物。 –
哦,這個領域是'not_analyzed'。鑑於它是'not_analyzed',我將嘗試''腳本「:」_source.blog_domain「,」 – Edmund