public function createMapFromTable($table) { $split = explode(".", $table); $type = $split[1]; if (mb_substr($type, 0, 1, 'utf-8') == "_") { $type = "a" . $type; } $table = new \app\models\Table($table); $schema = $table->getMapForEs(); $map = array("mappings" => array($type => array("properties" => array("properties" => array("type" => "object", "properties" => array()), "geometry" => array())))); foreach ($schema as $key => $value) { if ($value["type"] == "geometry") { $map["mappings"][$type]["properties"]["geometry"] = array("type" => "geo_shape"); } elseif ($value["type"] == "string" || $value["type"] == "text") { $map["mappings"][$type]["properties"]["properties"]["properties"][$key] = array("type" => "string", "search_analyzer" => "str_search_analyzer", "index_analyzer" => "str_index_analyzer"); } elseif ($value["type"] == "timestamptz") { $map["mappings"][$type]["properties"]["properties"]["properties"][$key] = array("type" => "date", "format" => "Y-MM-dd HH:mm:ss.SSSSSSZ"); } elseif ($value["type"] == "date") { $map["mappings"][$type]["properties"]["properties"]["properties"][$key] = array("type" => "date"); } elseif ($value["type"] == "int") { $map["mappings"][$type]["properties"]["properties"]["properties"][$key] = array("type" => "integer"); } elseif ($value["type"] == "number") { $map["mappings"][$type]["properties"]["properties"]["properties"][$key] = array("type" => "float"); } elseif ($value["type"] == "boolean") { $map["mappings"][$type]["properties"]["properties"]["properties"][$key] = array("type" => "boolean"); } } $response = array("map" => $map); return $response["map"]["mappings"]; }
public function createMapFromTable($table) { $split = explode(".", $table); $type = $split[1]; if (mb_substr($type, 0, 1, 'utf-8') == "_") { $type = "a" . $type; } $tableObj = new \app\models\Table($table); $schema = $tableObj->getMapForEs(); $map = array("mappings" => array($type => array("properties" => array("properties" => array("type" => "object", "properties" => array()))))); $layer = new \app\models\Layer(); $esTypes = $layer->getElasticsearchMapping($table); $arr = array(); foreach ($esTypes["data"] as $key => $value) { $arr[$value["column"]] = array("elasticsearchtype" => $value["elasticsearchtype"], "format" => $value["format"], "index" => $value["index"], "analyzer" => $value["analyzer"], "index_analyzer" => $value["index_analyzer"], "search_analyzer" => $value["search_analyzer"], "type" => $value["type"], "boost" => $value["boost"], "null_value" => $value["null_value"]); } foreach ($schema as $key => $value) { $pgType = $value["type"]; $mapArr = array(); $mapArr["type"] = $arr[$key]["elasticsearchtype"]; if (isset($arr[$key]["format"]) && $arr[$key]["format"]) { $mapArr["format"] = $arr[$key]["format"]; } if (isset($arr[$key]["index"]) && $arr[$key]["index"]) { $mapArr["index"] = $arr[$key]["index"]; } if (isset($arr[$key]["analyzer"]) && $arr[$key]["analyzer"]) { $mapArr["analyzer"] = $arr[$key]["analyzer"]; } if (isset($arr[$key]["search_analyzer"]) && $arr[$key]["search_analyzer"]) { $mapArr["search_analyzer"] = $arr[$key]["search_analyzer"]; } if (isset($arr[$key]["index_analyzer"]) && $arr[$key]["index_analyzer"]) { $mapArr["index_analyzer"] = $arr[$key]["index_analyzer"]; } if (isset($arr[$key]["boost"]) && $arr[$key]["boost"]) { $mapArr["boost"] = $arr[$key]["boost"]; } if (isset($arr[$key]["null_value"]) && $arr[$key]["null_value"]) { $mapArr["null_value"] = $arr[$key]["null_value"]; } if ($pgType == "geometry") { if ($mapArr["type"] == "geo_point") { $map["mappings"][$type]["properties"]["geometry"]["properties"]["coordinates"] = $mapArr; } else { $map["mappings"][$type]["properties"]["geometry"] = $mapArr; } } else { $map["mappings"][$type]["properties"]["properties"]["properties"][$key] = $mapArr; } } $response = array("map" => $map); return $response["map"]["mappings"]; }