fixes an error when fetching mappings

This commit is contained in:
Spencer Alger 2014-01-22 20:56:37 -07:00 committed by Boaz Leskes
parent f207d35fa0
commit 82735f0c96
2 changed files with 27 additions and 3 deletions

View file

@ -162,6 +162,10 @@ define([
per_index_types = {};
$.each(mappings, function (index, index_mapping) {
var normalized_index_mappings = {};
// 1.0.0 mapping format has changed, extract underlying mapping
if (index_mapping.mappings && _.keys(index_mapping).length === 1) {
index_mapping = index_mapping.mappings;
}
$.each(index_mapping, function (type_name, type_mapping) {
var field_list = getFieldNamesFromTypeMapping(type_mapping);
normalized_index_mappings[type_name] = field_list;

View file

@ -71,6 +71,26 @@ define([
deepEqual(mappings.getFields("index").sort(fc), [f("number", "int"), f("str", "string") ]);
});
test("Simple fields - 1.0 style", function () {
mappings.loadMappings({
"index": {
"mappings": {
"tweet": {
"properties": {
"str": {
"type": "string"
},
"number": {
"type": "int"
}
}
}
}
}
});
deepEqual(mappings.getFields("index").sort(fc), [f("number", "int"), f("str", "string") ]);
});
test("Nested fields", function () {
mappings.loadMappings({
@ -208,13 +228,13 @@ define([
});
deepEqual(mappings.getIndices().sort(),
[ "_all", "alias1", "alias2", "test_index1", "test_index2" ]
[ "_all", "alias1", "alias2", "test_index1", "test_index2" ]
);
deepEqual(mappings.getIndices(false).sort(),
["test_index1", "test_index2" ]
["test_index1", "test_index2" ]
);
deepEqual(mappings.expandAliases(["alias1", "test_index2"]).sort(),
["test_index1", "test_index2" ]
["test_index1", "test_index2" ]
);
deepEqual(mappings.expandAliases("alias2"), "test_index2");
});