2014-02-12 63 views
3

的名字,我有這種形式的數據:ElasticSearch - 點現場嵌套的對象

{ 
    "workers": { 
    "worker.1": { 
     "jobs": 1234 
    }, 
    }, 
    "total_jobs": 1234 
} 

,我試圖處理具有字段名「點」。我想這個映射:

{ 
    "worker_stats": { 
    "properties": { 
     "workers": { 
     "type": "object", 
     "properties": { 
      "worker.1": { 
      "type": "nested", 
      "index_name": "worker_1", 
      "properties": { 
       "jobs": { 
       "type": "integer" 
       } 
      } 
      } 
     } 
     }, 
     "total_jobs": { 
     "type": "integer" 
     } 
    } 
    } 
} 

但是當我取回我的映射,INDEX_NAME是無在哪裏可以看到,當我添加文檔,它還是得到了點。

最終,我只是試圖做一些彙總:

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "match_all": {} 
     } 
    } 
    }, 
    "aggs": { 
    "worker1_stats": { 
     "aggs": { 
     "stats": { 
      "stats": { 
      "field": "workers.worker.1.jobs" 
      } 
     } 
     }, 
     "nested": { 
     "path": "workers.worker.1" 
     } 
    } 
    } 
} 

但點干擾。

我該如何處理這個點?有沒有辦法使用script而不是field? (是我使用的nested即使正確

+0

有趣的是,我只是試過這個,它非常適用於非嵌套字段。 1.0.0 RC2有'''copy_to'''字段可能工作。 [鏈接到ES doco就可以了](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to) – mconlin

回答

0

我想你可以使用一個index_namepathtype : object在映射改變索引過程中字段的名稱

這裏是我的呢?例如:。

PUT /twitter/ 
{ 
    "settings" : { 
     "number_of_shards" : 5, 
     "number_of_replicas" : 0 
    }, 
    "mappings": { 
     "tweet":{ 
      "properties": { 
       "desc.youbet":{"type":"object","path":"just_name", 
       "properties": { 
        "one": { 
        "type": "integer", "index_name":"one" 
        } 
       } 
       } 
      } 
     } 
    } 
} 

PUT /twitter/tweet/1 
{ 
    "name":"chicken", 
    "desc.youbet":{ 
     "one":1, 
    } 
} 

PUT /twitter/tweet/2 
{ 
    "name":"chicken", 
    "desc.youbet":{ 
     "one":1, 
    } 
} 

現在可以用來說明對做業務和搜索的內容是一個文檔,以便在此:

POST /twitter/tweet/_search 
{ 
    "query": {"match_all": {}}, 
    "aggs":{ 
     "stats": { 
      "stats": {"field": "one"} 
     } 
    }, "size":0 
} 

結果是這樣的:

{ 
    "took": 2, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 2, 
     "max_score": 0, 
     "hits": [] 
    }, 
    "aggregations": { 
     "stats": { 
     "count": 2, 
     "min": 1, 
     "max": 1, 
     "avg": 1, 
     "sum": 2 
     } 
    } 
}