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