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