LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/elastic - ogrelasticdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 27 27 100.0 %
Date: 2025-09-10 17:48:50 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.14