Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: Elasticsearch Translator 4 : * Purpose: 5 : * Author: 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2011, Adam Estrada 9 : * 10 : * Permission is hereby granted, free of charge, to any person obtaining a 11 : * copy of this software and associated documentation files (the "Software"), 12 : * to deal in the Software without restriction, including without limitation 13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 : * and/or sell copies of the Software, and to permit persons to whom the 15 : * Software is furnished to do so, subject to the following conditions: 16 : * 17 : * The above copyright notice and this permission notice shall be included 18 : * in all copies or substantial portions of the Software. 19 : * 20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 : * DEALINGS IN THE SOFTWARE. 27 : ****************************************************************************/ 28 : 29 : #include "ogrsf_frmts.h" 30 : 31 : #include "ogrelasticdrivercore.h" 32 : 33 : /************************************************************************/ 34 : /* OGRElasticsearchDriverIdentify() */ 35 : /************************************************************************/ 36 : 37 42281 : int OGRElasticsearchDriverIdentify(GDALOpenInfo *poOpenInfo) 38 : 39 : { 40 42281 : return STARTS_WITH_CI(poOpenInfo->pszFilename, "ES:"); 41 : } 42 : 43 : /************************************************************************/ 44 : /* OGRElasticsearchDriverSetCommonMetadata() */ 45 : /************************************************************************/ 46 : 47 1222 : void OGRElasticsearchDriverSetCommonMetadata(GDALDriver *poDriver) 48 : { 49 1222 : poDriver->SetDescription(DRIVER_NAME); 50 1222 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 51 1222 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 52 1222 : poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES"); 53 1222 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 54 1222 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Elastic Search"); 55 1222 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, 56 1222 : "drivers/vector/elasticsearch.html"); 57 1222 : poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "ES:"); 58 1222 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONOPTIONLIST, 59 1222 : "<CreationOptionList/>"); 60 1222 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, 61 1222 : "OGRSQL SQLITE ES"); 62 : 63 1222 : poDriver->SetMetadataItem( 64 : GDAL_DS_LAYER_CREATIONOPTIONLIST, 65 : "<LayerCreationOptionList>" 66 : " <Option name='INDEX_NAME' type='string' description='Name of the " 67 : "index to create (or reuse). By default the index name is the layer " 68 : "name.'/>" 69 : " <Option name='INDEX_DEFINITION' type='string' description='Filename " 70 : "from which to read a user-defined index definition, or index " 71 : "definition as serialized JSon.'/>" 72 : " <Option name='MAPPING_NAME' type='string' description='(ES < 7) " 73 : "Name of the mapping type within the index.' " 74 : "default='FeatureCollection'/>" 75 : " <Option name='MAPPING' type='string' description='Filename from " 76 : "which to read a user-defined mapping, or mapping as serialized " 77 : "JSon.'/>" 78 : " <Option name='WRITE_MAPPING' type='string' description='Filename " 79 : "where to write the OGR generated mapping.'/>" 80 : " <Option name='OVERWRITE' type='boolean' description='Whether to " 81 : "overwrite an existing type mapping with the layer name to be created' " 82 : "default='NO'/>" 83 : " <Option name='OVERWRITE_INDEX' type='boolean' description='Whether " 84 : "to overwrite the whole index to which the layer belongs to' " 85 : "default='NO'/>" 86 : " <Option name='GEOMETRY_NAME' type='string' description='Name of " 87 : "geometry column.' default='geometry'/>" 88 : " <Option name='GEOM_MAPPING_TYPE' type='string-select' " 89 : "description='Mapping type for geometry fields' default='AUTO'>" 90 : " <Value>AUTO</Value>" 91 : " <Value>GEO_POINT</Value>" 92 : " <Value>GEO_SHAPE</Value>" 93 : " </Option>" 94 : " <Option name='GEO_SHAPE_ENCODING' type='string-select' " 95 : "description='Encoding for geo_shape geometry fields' " 96 : "default='GeoJSON'>" 97 : " <Value>GeoJSON</Value>" 98 : " <Value>WKT</Value>" 99 : " </Option>" 100 : " <Option name='GEOM_PRECISION' type='string' description='Desired " 101 : "geometry precision. Number followed by unit. For example 1m'/>" 102 : " <Option name='STORE_FIELDS' type='boolean' description='Whether " 103 : "fields should be stored in the index' default='NO'/>" 104 : " <Option name='STORED_FIELDS' type='string' description='List of " 105 : "comma separated field names that should be stored in the index'/>" 106 : " <Option name='NOT_ANALYZED_FIELDS' type='string' description='List " 107 : "of comma separated field names that should not be analyzed during " 108 : "indexing, or {ALL}'/>" 109 : " <Option name='NOT_INDEXED_FIELDS' type='string' description='List " 110 : "of comma separated field names that should not be indexed'/>" 111 : " <Option name='FIELDS_WITH_RAW_VALUE' type='string' " 112 : "description='List of comma separated field names (of type string) " 113 : "that should have an additional raw/not_analyzed field, or {ALL}'/>" 114 : " <Option name='BULK_INSERT' type='boolean' description='Whether to " 115 : "use bulk insert for feature creation' default='YES'/>" 116 : " <Option name='BULK_SIZE' type='integer' description='Size in bytes " 117 : "of the buffer for bulk upload' default='1000000'/>" 118 : " <Option name='DOT_AS_NESTED_FIELD' type='boolean' " 119 : "description='Whether to consider dot character in field name as " 120 : "sub-document' default='YES'/>" 121 : " <Option name='IGNORE_SOURCE_ID' type='boolean' description='Whether " 122 : "to ignore _id field in features passed to CreateFeature()' " 123 : "default='NO'/>" 124 : " <Option name='FID' type='string' description='Field name, with " 125 : "integer values, to use as FID' default='ogc_fid'/>" 126 1222 : "</LayerCreationOptionList>"); 127 : 128 1222 : poDriver->SetMetadataItem( 129 : GDAL_DMD_OPENOPTIONLIST, 130 : "<OpenOptionList>" 131 : " <Option name='HOST' type='string' description='Server hostname' " 132 : "default='localhost'/>" 133 : " <Option name='PORT' type='integer' description='Server port' " 134 : "default='9200'/>" 135 : " <Option name='USERPWD' type='string' " 136 : "description='Basic authentication as username:password'/>" 137 : " <Option name='LAYER' type='string' description='Index name or " 138 : "index_mapping to use for restricting layer listing'/>" 139 : " <Option name='AGGREGATION' type='string' description='JSon " 140 : "serialized description of an aggregation request'/>" 141 : " <Option name='BATCH_SIZE' type='integer' description='Number of " 142 : "features to retrieve per batch' default='100'/>" 143 : " <Option name='FEATURE_COUNT_TO_ESTABLISH_FEATURE_DEFN' " 144 : "type='integer' description='Number of features to retrieve to " 145 : "establish feature definition. -1 = unlimited' default='100'/>" 146 : " <Option name='SINGLE_QUERY_TIMEOUT' type='float' " 147 : "description='Timeout in second for request such as GetFeatureCount() " 148 : "or GetExtent()'/>" 149 : " <Option name='SINGLE_QUERY_TERMINATE_AFTER' type='integer' " 150 : "description='Maximum number of documents to collect for request such " 151 : "as GetFeatureCount() or GetExtent()'/>" 152 : " <Option name='FEATURE_ITERATION_TIMEOUT' type='float' " 153 : "description='Timeout in second for feature iteration'/>" 154 : " <Option name='FEATURE_ITERATION_TERMINATE_AFTER' type='integer' " 155 : "description='Maximum number of documents to collect for feature " 156 : "iteration'/>" 157 : " <Option name='JSON_FIELD' type='boolean' description='Whether to " 158 : "include a field with the full document as JSON' default='NO'/>" 159 : " <Option name='FLATTEN_NESTED_ATTRIBUTES' type='boolean' " 160 : "description='Whether to recursively explore nested objects and " 161 : "produce flatten OGR attributes' default='YES'/>" 162 : " <Option name='BULK_INSERT' type='boolean' description='Whether to " 163 : "use bulk insert for feature creation' default='YES'/>" 164 : " <Option name='BULK_SIZE' type='integer' description='Size in bytes " 165 : "of the buffer for bulk upload' default='1000000'/>" 166 : " <Option name='FID' type='string' description='Field name, with " 167 : "integer values, to use as FID' default='ogc_fid'/>" 168 : " <Option name='FORWARD_HTTP_HEADERS_FROM_ENV' type='string' " 169 : "description='Comma separated list of " 170 : "http_header_name=env_variable_name'/>" 171 : " <Option name='ADD_SOURCE_INDEX_NAME' type='boolean' " 172 : "description='Whether to add the index name as a field for wildcard " 173 : "layers' default='NO'/>" 174 1222 : "</OpenOptionList>"); 175 : 176 1222 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATATYPES, 177 : "Integer Integer64 Real String Date DateTime " 178 : "Time IntegerList Integer64List RealList " 179 1222 : "StringList Binary"); 180 : 181 1222 : poDriver->pfnIdentify = OGRElasticsearchDriverIdentify; 182 1222 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 183 1222 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES"); 184 1222 : } 185 : 186 : /************************************************************************/ 187 : /* DeclareDeferredOGRElasticPlugin() */ 188 : /************************************************************************/ 189 : 190 : #ifdef PLUGIN_FILENAME 191 : void DeclareDeferredOGRElasticPlugin() 192 : { 193 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 194 : { 195 : return; 196 : } 197 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 198 : #ifdef PLUGIN_INSTALLATION_MESSAGE 199 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 200 : PLUGIN_INSTALLATION_MESSAGE); 201 : #endif 202 : OGRElasticsearchDriverSetCommonMetadata(poDriver); 203 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 204 : } 205 : #endif