你所說的「類型」究竟是「映射類型」,並得到他們的方法就是使用:
curl -XGET localhost:9200/_all/_mapping
現在,因爲你只需要映射類型的名稱,你不」噸需要安裝任何軟件,你可以使用簡單地使用Python來只得到你想要的是以前的反應是什麼:
curl -XGET localhost:9205/_all/_mapping | python -c 'import json,sys; indices=json.load(sys.stdin); indices = [type for index in indices for type in indices.get(index).get("mappings")]; print list(indices);'
的Python腳本做了很簡單的,也就是說,它遍歷所有索引和映射類型,只檢索後者的名字:
import json,sys;
resp = json.load(sys.stdin);
indices = [type for index in resp for type in indices.get(index).get("mappings")];
print list(indices);'
UPDATE
由於您使用的紅寶石,同樣的招數可通過使用Ruby代碼:
curl -XGET localhost:9205/_all/_mapping | ruby -e "require 'rubygems'; require 'json'; resp = JSON.parse(STDIN.read); resp.each { |index, indexSpec | indexSpec['mappings'].each {|type, fields| puts type} }"
的Ruby腳本是這樣的:
require 'rubygems';
require 'json';
resp = JSON.parse(STDIN.read);
resp.each { |index, indexSpec |
indexSpec['mappings'].each { |type, fields|
puts type
}
}
來源
2015-12-08 04:09:07
Val
ES中沒有'_type' ,如果你只對類型感興趣,那麼看看@Andrew White的[在這裏回答](http://stackoverflow.com/questions/31087204/get-all-index-and-types-names-from-cluster-in -elasticsearch)你需要[安裝jq](https://stedolan.github.io/jq/download/)爲 – ChintanShah25