From 3d06a964baee37c9239ec28f063c28971bb712a9 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 21 Apr 2022 15:38:31 +0100 Subject: [PATCH] Various improvements and clean up (#6371) * Add deserialisation test for DataStreamNames * Type cleanup and sealing * Update FieldValues * Descriptor cleanup * Document path * Initial Fields cleanup * TaskId cleanup * Lots of cleanup * Lots of sealing * Code generator seals more types * Extract out types from future generated * Reorg serialization types * Skip v7 folder * Fix BOM --- .../AsyncSearchStatusResponse.cs | 0 .../AsyncSearch/AsyncSearchSubmitRequest.cs | 33 + .../Api/AsyncSearch/GetAsyncSearchRequest.cs | 24 + .../GetAsyncSearchResponse.cs | 0 .../Api/AsyncSearchSubmitRequestDescriptor.cs | 13 - .../Api/BulkRequest.cs | 256 ++ .../Api/BulkResponse.cs | 34 + .../Api/BulkResponseItemBase.cs | 27 + .../Api/CountRequest.cs | 41 + .../Api/CreateRequest.cs | 23 + .../Api/DeleteRequest.cs | 17 + .../Api/Eql/GetEqlResponse.cs | 27 + .../Api/SearchRequest.cs | 72 + .../Api/SourceRequest.cs | 24 + .../Api/SourceResponse.cs | 30 + .../Api/{ => Sql}/SqlGetAsyncResponse.cs | 0 .../Api/{ => Sql}/SqlQueryResponse.cs | 0 .../Api/UpdateRequestDescriptor.cs | 17 + .../Client/ElasticsearchClient-BulkAll.cs | 19 - .../Client/ElasticsearchClient-Manual.cs | 92 + .../Client/ElasticsearchClient.cs | 2 +- .../Common/Aggregations/AggregationBase.cs | 2 +- .../Aggregations/AggregationCombinator.cs | 2 +- .../Aggregations/AggregationDictionary.cs | 2 +- .../Configuration/ClrPropertyMapping.cs | 59 +- .../Configuration/MemberInfoResolver.cs | 2 +- .../Containers/ContainerAndVariantBase.cs | 14 + .../Common/Containers/ContainerBase.cs | 122 +- .../Common/Containers/ContainerVariantBase.cs | 19 + .../IContainer.cs} | 7 +- .../Common/Containers/IContainerVariant.cs | 10 + .../Containers/VariantDescriptorBase.cs | 12 + .../Common/Fields/FieldValues.cs | 6 +- .../Common/Fluent/DescriptorBase.cs | 103 +- .../Common/ForAttribute.cs | 109 - .../Common/Infer/DocumentPath/DocumentPath.cs | 151 +- .../Common/Infer/Field/Field.cs | 289 +- .../Infer/Field/FieldExpressionVisitor.cs | 4 - .../Common/Infer/Fields/Fields.cs | 2 +- .../Common/Infer/IndexUuid/IndexUuid.cs | 48 - .../Common/Infer/Indices/Indices.cs | 2 +- .../Common/Infer/Inferrer.cs | 144 +- .../Common/Infer/Name/Name.cs | 91 - .../Common/Infer/PropertyName/PropertyName.cs | 10 +- .../Common/Infer/RelationName/RelationName.cs | 133 +- .../RelationName/RelationNameResolver.cs | 86 +- .../Common/Infer/Timestamp/Timestamp.cs | 21 +- .../Common/IsADictionaryBase.cs | 4 +- .../Common/MinimumShouldMatch.cs | 2 +- .../Common/ReadOnlyIndexNameDictionary.cs | 61 + .../Common/Request/IProxyRequest.cs | 2 +- .../Common/Request/PlainRequestBase.cs | 143 + .../Common/Request/RouteValues.cs | 2 +- .../Common/TaggedUnion.cs | 44 - .../Common/TextToAnalyze.cs | 14 - .../Common/TimeUnit/Time.cs | 2 +- .../Common/Union/Union.cs | 2 - .../DataStreamNames/DataStreamName.cs | 0 .../DataStreamNames/DataStreamNames.cs | 0 .../UrlParameters/IndexAlias/IndexAlias.cs | 78 + .../UrlParameters/IndexUuid/IndexUuid.cs | 53 + .../Common/UrlParameters/Name/Name.cs | 50 + .../{Infer => UrlParameters}/Name/Names.cs | 2 +- .../NodeIds}/NodeIds.cs | 2 +- .../{Infer => UrlParameters}/TaskId/TaskId.cs | 20 +- .../Common/UrlParameters/Username/Username.cs | 50 + .../CommonOptions/TimeUnit/Time.cs | 356 --- .../FutureGenerated/DesignPrototype.cs | 758 ------ .../FutureGenerated/FieldType.cs | 56 + .../FutureGenerated/FutureGenerated.cs | 2314 +---------------- .../Helpers/BulkAllObservable.cs | 19 +- .../Helpers/BulkAllObserver.cs | 2 +- .../Helpers/BulkAllResponse.cs | 2 +- .../Helpers/CoordinatedRequestObserverBase.cs | 2 +- .../Helpers/ProducerConsumerBackPressure.cs | 2 +- ...AggregationContainerSerializationHelper.cs | 343 --- .../Serialization/FieldNameQueryAttribute.cs | 16 + .../IDictionaryKey.cs} | 12 +- .../{JsonWriter.cs => ISourceMarker.cs} | 4 +- .../Serialization/IStreamSerializable.cs | 33 + .../Serialization/IgnoreAttribute.cs | 11 + .../InterfaceConverterAttribute.cs | 17 + ...ribute.cs => InterfaceConverterFactory.cs} | 31 - .../Serialization/IntermediateConverter.cs | 28 + .../IntermediateSourceConverter.cs | 36 + .../Serialization/IsADictionaryConverter.cs | 1 - .../ReadOnlyIndexNameDictionaryConverter.cs | 38 + ...OnlyIndexNameDictionaryConverterFactory.cs | 32 + .../ResolvableDictionaryFormatterFactory.cs | 17 + .../Serialization/SelfSerializable.cs | 27 + .../SelfSerializableConverterFactory.cs | 2 - .../Serialization/SerializationConstants.cs | 11 + .../Serialization/SimpleInterfaceConverter.cs | 19 + .../Serialization/SourceConverter.cs | 24 + .../Serialization/SourceConverterAttribute.cs | 14 + .../Serialization/SourceConverterFactory.cs | 32 + .../Serialization/SourceMarker.cs | 11 + .../StatefulSerializerExtensions.cs | 48 - .../Serialization/StringEnumAttribute.cs | 11 + .../TermsAggregateSerializationHelper.cs | 85 + .../Serialization/UnionConverter.cs | 29 - .../Types/Aggregations/AggregateDictionary.cs | 89 + .../Aggregations/AggregationContainer.cs | 63 + .../AggregationContainerDescriptor.cs | 41 + .../Types/Aggregations/EmptyTermsAggregate.cs | 10 + .../Types/Aggregations/EmptyTermsBucket.cs | 8 + .../Aggregations/MultiBucketAggregateBase.cs | 16 + .../Types/Aggregations/TermsAggregate.cs | 10 + .../Types/Aggregations/TermsBucket.cs | 12 + .../{Api => Types/AsyncSearch}/AsyncSearch.cs | 0 .../Types/OpType.cs | 22 + .../Types/PointInTimeReferenceDescriptor.cs | 11 + .../QueryDsl/QueryContainerDescriptor.cs | 31 + .../CommonOptions/Range => Types}/Ranges.cs | 0 .../Types/Refresh.cs | 21 + .../Types/Scripting/InlineScript.cs | 98 + .../Types/Scripting/InlineScriptDescriptor.cs | 11 + .../Types/Scripting/ScriptDescriptor.cs | 43 + .../Types/SourceConfig.cs | 64 + .../Types/StoredScriptId.cs | 11 + .../Types/TermsOrder.cs | 102 + .../Types/WaitForActiveShards.cs | 22 + .../AsyncSearch/AsyncSearchStatusRequest.g.cs | 2 +- .../AsyncSearchStatusResponse.g.cs | 2 +- .../AsyncSearch/AsyncSearchSubmitRequest.g.cs | 2 +- .../AsyncSearchSubmitResponse.g.cs | 2 +- .../AsyncSearch/DeleteAsyncSearchRequest.g.cs | 2 +- .../DeleteAsyncSearchResponse.g.cs | 2 +- .../AsyncSearch/GetAsyncSearchRequest.g.cs | 2 +- .../AsyncSearch/GetAsyncSearchResponse.g.cs | 2 +- ...scalingDeleteAutoscalingPolicyRequest.g.cs | 2 +- ...calingDeleteAutoscalingPolicyResponse.g.cs | 2 +- ...oscalingGetAutoscalingCapacityRequest.g.cs | 2 +- ...scalingGetAutoscalingCapacityResponse.g.cs | 2 +- ...utoscalingGetAutoscalingPolicyRequest.g.cs | 2 +- ...toscalingGetAutoscalingPolicyResponse.g.cs | 2 +- ...utoscalingPutAutoscalingPolicyRequest.g.cs | 2 +- ...toscalingPutAutoscalingPolicyResponse.g.cs | 2 +- .../_Generated/Api/BulkRequest.g.cs | 2 +- .../_Generated/Api/BulkResponse.g.cs | 2 +- .../CcrDeleteAutoFollowPatternRequest.g.cs | 2 +- .../CcrDeleteAutoFollowPatternResponse.g.cs | 2 +- .../Api/Ccr/CcrFollowInfoRequest.g.cs | 2 +- .../Api/Ccr/CcrFollowInfoResponse.g.cs | 2 +- .../_Generated/Api/Ccr/CcrFollowRequest.g.cs | 2 +- .../_Generated/Api/Ccr/CcrFollowResponse.g.cs | 2 +- .../Api/Ccr/CcrFollowStatsRequest.g.cs | 2 +- .../Api/Ccr/CcrFollowStatsResponse.g.cs | 2 +- .../Api/Ccr/CcrForgetFollowerRequest.g.cs | 2 +- .../Api/Ccr/CcrForgetFollowerResponse.g.cs | 2 +- .../Ccr/CcrGetAutoFollowPatternRequest.g.cs | 2 +- .../Ccr/CcrGetAutoFollowPatternResponse.g.cs | 2 +- .../Ccr/CcrPauseAutoFollowPatternRequest.g.cs | 2 +- .../CcrPauseAutoFollowPatternResponse.g.cs | 2 +- .../Api/Ccr/CcrPauseFollowRequest.g.cs | 2 +- .../Api/Ccr/CcrPauseFollowResponse.g.cs | 2 +- .../Ccr/CcrPutAutoFollowPatternRequest.g.cs | 2 +- .../Ccr/CcrPutAutoFollowPatternResponse.g.cs | 2 +- .../CcrResumeAutoFollowPatternRequest.g.cs | 2 +- .../CcrResumeAutoFollowPatternResponse.g.cs | 2 +- .../Api/Ccr/CcrResumeFollowRequest.g.cs | 2 +- .../Api/Ccr/CcrResumeFollowResponse.g.cs | 2 +- .../_Generated/Api/Ccr/CcrStatsRequest.g.cs | 2 +- .../_Generated/Api/Ccr/CcrStatsResponse.g.cs | 2 +- .../Api/Ccr/CcrUnfollowRequest.g.cs | 2 +- .../Api/Ccr/CcrUnfollowResponse.g.cs | 2 +- .../_Generated/Api/ClearScrollRequest.g.cs | 2 +- .../_Generated/Api/ClearScrollResponse.g.cs | 2 +- .../Api/ClosePointInTimeRequest.g.cs | 2 +- .../Api/ClosePointInTimeResponse.g.cs | 2 +- .../ClusterAllocationExplainRequest.g.cs | 2 +- .../ClusterAllocationExplainResponse.g.cs | 2 +- ...ClusterDeleteComponentTemplateRequest.g.cs | 2 +- ...lusterDeleteComponentTemplateResponse.g.cs | 2 +- ...erDeleteVotingConfigExclusionsRequest.g.cs | 2 +- ...rDeleteVotingConfigExclusionsResponse.g.cs | 2 +- ...ClusterExistsComponentTemplateRequest.g.cs | 2 +- ...lusterExistsComponentTemplateResponse.g.cs | 2 +- .../ClusterGetComponentTemplateRequest.g.cs | 2 +- .../ClusterGetComponentTemplateResponse.g.cs | 2 +- .../Cluster/ClusterGetSettingsRequest.g.cs | 2 +- .../Cluster/ClusterGetSettingsResponse.g.cs | 2 +- .../Api/Cluster/ClusterHealthRequest.g.cs | 2 +- .../Api/Cluster/ClusterHealthResponse.g.cs | 2 +- .../Cluster/ClusterPendingTasksRequest.g.cs | 2 +- .../Cluster/ClusterPendingTasksResponse.g.cs | 2 +- ...sterPostVotingConfigExclusionsRequest.g.cs | 2 +- ...terPostVotingConfigExclusionsResponse.g.cs | 2 +- .../ClusterPutComponentTemplateRequest.g.cs | 2 +- .../ClusterPutComponentTemplateResponse.g.cs | 2 +- .../Cluster/ClusterPutSettingsRequest.g.cs | 2 +- .../Cluster/ClusterPutSettingsResponse.g.cs | 2 +- .../Api/Cluster/ClusterRemoteInfoRequest.g.cs | 2 +- .../Cluster/ClusterRemoteInfoResponse.g.cs | 2 +- .../Api/Cluster/ClusterRerouteRequest.g.cs | 2 +- .../Api/Cluster/ClusterRerouteResponse.g.cs | 2 +- .../Api/Cluster/ClusterStateRequest.g.cs | 2 +- .../Api/Cluster/ClusterStateResponse.g.cs | 2 +- .../Api/Cluster/ClusterStatsRequest.g.cs | 2 +- .../Api/Cluster/ClusterStatsResponse.g.cs | 2 +- .../_Generated/Api/CountRequest.g.cs | 2 +- .../_Generated/Api/CountResponse.g.cs | 2 +- .../_Generated/Api/CreateRequest.g.cs | 2 +- .../_Generated/Api/CreateResponse.g.cs | 2 +- ...lingIndicesListDanglingIndicesRequest.g.cs | 2 +- ...ingIndicesListDanglingIndicesResponse.g.cs | 2 +- .../_Generated/Api/DeleteByQueryRequest.g.cs | 2 +- .../_Generated/Api/DeleteByQueryResponse.g.cs | 2 +- .../Api/DeleteByQueryRethrottleRequest.g.cs | 2 +- .../Api/DeleteByQueryRethrottleResponse.g.cs | 2 +- .../_Generated/Api/DeleteRequest.g.cs | 2 +- .../_Generated/Api/DeleteResponse.g.cs | 2 +- .../_Generated/Api/DeleteScriptRequest.g.cs | 2 +- .../_Generated/Api/DeleteScriptResponse.g.cs | 2 +- .../Api/Enrich/EnrichDeletePolicyRequest.g.cs | 2 +- .../Enrich/EnrichDeletePolicyResponse.g.cs | 2 +- .../Enrich/EnrichExecutePolicyRequest.g.cs | 2 +- .../Enrich/EnrichExecutePolicyResponse.g.cs | 2 +- .../Api/Enrich/EnrichGetPolicyRequest.g.cs | 2 +- .../Api/Enrich/EnrichGetPolicyResponse.g.cs | 2 +- .../Api/Enrich/EnrichPutPolicyRequest.g.cs | 2 +- .../Api/Enrich/EnrichPutPolicyResponse.g.cs | 2 +- .../Api/Enrich/EnrichStatsRequest.g.cs | 2 +- .../Api/Enrich/EnrichStatsResponse.g.cs | 2 +- .../_Generated/Api/Eql/DeleteEqlRequest.g.cs | 2 +- .../_Generated/Api/Eql/DeleteEqlResponse.g.cs | 2 +- .../Api/Eql/EqlGetStatusRequest.g.cs | 2 +- .../Api/Eql/EqlGetStatusResponse.g.cs | 2 +- .../_Generated/Api/Eql/EqlSearchRequest.g.cs | 2 +- .../_Generated/Api/Eql/EqlSearchResponse.g.cs | 2 +- .../_Generated/Api/Eql/GetEqlRequest.g.cs | 2 +- .../_Generated/Api/Eql/GetEqlResponse.g.cs | 2 +- .../_Generated/Api/ExistsRequest.g.cs | 2 +- .../_Generated/Api/ExistsResponse.g.cs | 2 +- .../_Generated/Api/ExistsSourceRequest.g.cs | 2 +- .../_Generated/Api/ExistsSourceResponse.g.cs | 2 +- .../_Generated/Api/ExplainRequest.g.cs | 2 +- .../_Generated/Api/ExplainResponse.g.cs | 2 +- .../Features/FeaturesGetFeaturesRequest.g.cs | 2 +- .../Features/FeaturesGetFeaturesResponse.g.cs | 2 +- .../_Generated/Api/FieldCapsRequest.g.cs | 2 +- .../_Generated/Api/FieldCapsResponse.g.cs | 2 +- .../_Generated/Api/GetRequest.g.cs | 2 +- .../_Generated/Api/GetResponse.g.cs | 2 +- .../Api/Graph/GraphExploreRequest.g.cs | 2 +- .../Api/Graph/GraphExploreResponse.g.cs | 2 +- .../Api/Ilm/IlmDeleteLifecycleRequest.g.cs | 2 +- .../Api/Ilm/IlmDeleteLifecycleResponse.g.cs | 2 +- .../Api/Ilm/IlmExplainLifecycleRequest.g.cs | 2 +- .../Api/Ilm/IlmExplainLifecycleResponse.g.cs | 2 +- .../Api/Ilm/IlmGetLifecycleRequest.g.cs | 2 +- .../Api/Ilm/IlmGetLifecycleResponse.g.cs | 2 +- .../Api/Ilm/IlmGetStatusRequest.g.cs | 2 +- .../Api/Ilm/IlmGetStatusResponse.g.cs | 2 +- .../Api/Ilm/IlmMigrateToDataTiersRequest.g.cs | 2 +- .../Ilm/IlmMigrateToDataTiersResponse.g.cs | 2 +- .../Api/Ilm/IlmMoveToStepRequest.g.cs | 2 +- .../Api/Ilm/IlmMoveToStepResponse.g.cs | 2 +- .../Api/Ilm/IlmPutLifecycleRequest.g.cs | 2 +- .../Api/Ilm/IlmPutLifecycleResponse.g.cs | 2 +- .../Api/Ilm/IlmRemovePolicyRequest.g.cs | 2 +- .../Api/Ilm/IlmRemovePolicyResponse.g.cs | 2 +- .../_Generated/Api/Ilm/IlmRetryRequest.g.cs | 2 +- .../_Generated/Api/Ilm/IlmRetryResponse.g.cs | 2 +- .../_Generated/Api/Ilm/IlmStartRequest.g.cs | 2 +- .../_Generated/Api/Ilm/IlmStartResponse.g.cs | 2 +- .../_Generated/Api/Ilm/IlmStopRequest.g.cs | 2 +- .../_Generated/Api/Ilm/IlmStopResponse.g.cs | 2 +- .../Api/IndexManagement/AliasRequest.g.cs | 2 +- .../Api/IndexManagement/AliasResponse.g.cs | 2 +- .../Api/IndexManagement/AnalyzeRequest.g.cs | 2 +- .../Api/IndexManagement/AnalyzeResponse.g.cs | 2 +- .../IndexManagement/ClearCacheRequest.g.cs | 2 +- .../IndexManagement/ClearCacheResponse.g.cs | 2 +- .../Api/IndexManagement/CloneRequest.g.cs | 2 +- .../Api/IndexManagement/CloneResponse.g.cs | 2 +- .../Api/IndexManagement/CloseRequest.g.cs | 2 +- .../Api/IndexManagement/CloseResponse.g.cs | 2 +- .../CreateDataStreamRequest.g.cs | 2 +- .../CreateDataStreamResponse.g.cs | 2 +- .../Api/IndexManagement/CreateRequest.g.cs | 2 +- .../Api/IndexManagement/CreateResponse.g.cs | 2 +- .../IndexManagement/DataStreamRequest.g.cs | 2 +- .../IndexManagement/DataStreamResponse.g.cs | 2 +- .../DataStreamsStatsRequest.g.cs | 2 +- .../DataStreamsStatsResponse.g.cs | 2 +- .../IndexManagement/DeleteAliasRequest.g.cs | 2 +- .../IndexManagement/DeleteAliasResponse.g.cs | 2 +- .../DeleteDataStreamRequest.g.cs | 2 +- .../DeleteDataStreamResponse.g.cs | 2 +- .../DeleteIndexTemplateRequest.g.cs | 2 +- .../DeleteIndexTemplateResponse.g.cs | 2 +- .../Api/IndexManagement/DeleteRequest.g.cs | 2 +- .../Api/IndexManagement/DeleteResponse.g.cs | 2 +- .../DeleteTemplateRequest.g.cs | 2 +- .../DeleteTemplateResponse.g.cs | 2 +- .../IndexManagement/ExistsAliasRequest.g.cs | 2 +- .../IndexManagement/ExistsAliasResponse.g.cs | 2 +- .../ExistsIndexTemplateRequest.g.cs | 2 +- .../ExistsIndexTemplateResponse.g.cs | 2 +- .../Api/IndexManagement/ExistsRequest.g.cs | 2 +- .../Api/IndexManagement/ExistsResponse.g.cs | 2 +- .../ExistsTemplateRequest.g.cs | 2 +- .../ExistsTemplateResponse.g.cs | 2 +- .../IndexManagement/FieldMappingRequest.g.cs | 2 +- .../IndexManagement/FieldMappingResponse.g.cs | 2 +- .../Api/IndexManagement/FlushRequest.g.cs | 2 +- .../Api/IndexManagement/FlushResponse.g.cs | 2 +- .../IndexManagement/ForcemergeRequest.g.cs | 2 +- .../IndexManagement/ForcemergeResponse.g.cs | 2 +- .../Api/IndexManagement/GetRequest.g.cs | 2 +- .../Api/IndexManagement/GetResponse.g.cs | 2 +- .../IndexManagement/IndexTemplateRequest.g.cs | 2 +- .../IndexTemplateResponse.g.cs | 2 +- .../Api/IndexManagement/MappingRequest.g.cs | 2 +- .../Api/IndexManagement/MappingResponse.g.cs | 2 +- .../MigrateToDataStreamRequest.g.cs | 2 +- .../MigrateToDataStreamResponse.g.cs | 2 +- .../Api/IndexManagement/OpenRequest.g.cs | 2 +- .../Api/IndexManagement/OpenResponse.g.cs | 2 +- .../PromoteDataStreamRequest.g.cs | 2 +- .../PromoteDataStreamResponse.g.cs | 2 +- .../Api/IndexManagement/PutAliasRequest.g.cs | 2 +- .../Api/IndexManagement/PutAliasResponse.g.cs | 2 +- .../PutIndexTemplateRequest.g.cs | 2 +- .../PutIndexTemplateResponse.g.cs | 2 +- .../IndexManagement/PutMappingRequest.g.cs | 2 +- .../IndexManagement/PutMappingResponse.g.cs | 2 +- .../IndexManagement/PutSettingsRequest.g.cs | 2 +- .../IndexManagement/PutSettingsResponse.g.cs | 2 +- .../IndexManagement/PutTemplateRequest.g.cs | 2 +- .../IndexManagement/PutTemplateResponse.g.cs | 2 +- .../Api/IndexManagement/RecoveryRequest.g.cs | 2 +- .../Api/IndexManagement/RecoveryResponse.g.cs | 2 +- .../Api/IndexManagement/RefreshRequest.g.cs | 2 +- .../Api/IndexManagement/RefreshResponse.g.cs | 2 +- .../ReloadSearchAnalyzersRequest.g.cs | 2 +- .../ReloadSearchAnalyzersResponse.g.cs | 2 +- .../IndexManagement/ResolveIndexRequest.g.cs | 2 +- .../IndexManagement/ResolveIndexResponse.g.cs | 2 +- .../Api/IndexManagement/RolloverRequest.g.cs | 2 +- .../Api/IndexManagement/RolloverResponse.g.cs | 2 +- .../Api/IndexManagement/SegmentsRequest.g.cs | 2 +- .../Api/IndexManagement/SegmentsResponse.g.cs | 2 +- .../Api/IndexManagement/SettingsRequest.g.cs | 2 +- .../Api/IndexManagement/SettingsResponse.g.cs | 2 +- .../IndexManagement/ShardStoresRequest.g.cs | 2 +- .../IndexManagement/ShardStoresResponse.g.cs | 2 +- .../Api/IndexManagement/ShrinkRequest.g.cs | 2 +- .../Api/IndexManagement/ShrinkResponse.g.cs | 2 +- .../SimulateIndexTemplateRequest.g.cs | 2 +- .../SimulateIndexTemplateResponse.g.cs | 2 +- .../SimulateTemplateRequest.g.cs | 2 +- .../SimulateTemplateResponse.g.cs | 2 +- .../Api/IndexManagement/SplitRequest.g.cs | 2 +- .../Api/IndexManagement/SplitResponse.g.cs | 2 +- .../Api/IndexManagement/StatsRequest.g.cs | 2 +- .../Api/IndexManagement/StatsResponse.g.cs | 2 +- .../Api/IndexManagement/TemplateRequest.g.cs | 2 +- .../Api/IndexManagement/TemplateResponse.g.cs | 2 +- .../IndexManagement/ValidateQueryRequest.g.cs | 2 +- .../ValidateQueryResponse.g.cs | 2 +- .../_Generated/Api/IndexRequest.g.cs | 2 +- .../_Generated/Api/IndexResponse.g.cs | 2 +- .../_Generated/Api/InfoRequest.g.cs | 2 +- .../_Generated/Api/InfoResponse.g.cs | 2 +- .../Ingest/IngestDeletePipelineRequest.g.cs | 2 +- .../Ingest/IngestDeletePipelineResponse.g.cs | 2 +- .../Api/Ingest/IngestGeoIpStatsRequest.g.cs | 2 +- .../Api/Ingest/IngestGeoIpStatsResponse.g.cs | 2 +- .../Api/Ingest/IngestGetPipelineRequest.g.cs | 2 +- .../Api/Ingest/IngestGetPipelineResponse.g.cs | 2 +- .../Ingest/IngestProcessorGrokRequest.g.cs | 2 +- .../Ingest/IngestProcessorGrokResponse.g.cs | 2 +- .../Api/Ingest/IngestPutPipelineRequest.g.cs | 2 +- .../Api/Ingest/IngestPutPipelineResponse.g.cs | 2 +- .../Api/Ingest/IngestSimulateRequest.g.cs | 2 +- .../Api/Ingest/IngestSimulateResponse.g.cs | 2 +- .../Api/License/DeleteLicenseRequest.g.cs | 2 +- .../Api/License/DeleteLicenseResponse.g.cs | 2 +- .../Api/License/GetLicenseRequest.g.cs | 2 +- .../Api/License/GetLicenseResponse.g.cs | 2 +- .../License/LicenseGetBasicStatusRequest.g.cs | 2 +- .../LicenseGetBasicStatusResponse.g.cs | 2 +- .../License/LicenseGetTrialStatusRequest.g.cs | 2 +- .../LicenseGetTrialStatusResponse.g.cs | 2 +- .../Api/License/LicensePostRequest.g.cs | 2 +- .../Api/License/LicensePostResponse.g.cs | 2 +- .../License/LicensePostStartBasicRequest.g.cs | 2 +- .../LicensePostStartBasicResponse.g.cs | 2 +- .../License/LicensePostStartTrialRequest.g.cs | 2 +- .../LicensePostStartTrialResponse.g.cs | 2 +- .../LogstashDeletePipelineRequest.g.cs | 2 +- .../LogstashDeletePipelineResponse.g.cs | 2 +- .../Logstash/LogstashPutPipelineRequest.g.cs | 2 +- .../Logstash/LogstashPutPipelineResponse.g.cs | 2 +- .../MigrationDeprecationsRequest.g.cs | 2 +- .../MigrationDeprecationsResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlCloseJobRequest.g.cs | 2 +- .../_Generated/Api/Ml/MlCloseJobResponse.g.cs | 2 +- .../Api/Ml/MlDeleteCalendarEventRequest.g.cs | 2 +- .../Api/Ml/MlDeleteCalendarEventResponse.g.cs | 2 +- .../Api/Ml/MlDeleteCalendarRequest.g.cs | 2 +- .../Api/Ml/MlDeleteCalendarResponse.g.cs | 2 +- .../Ml/MlDeleteDataFrameAnalyticsRequest.g.cs | 2 +- .../MlDeleteDataFrameAnalyticsResponse.g.cs | 2 +- .../Api/Ml/MlDeleteDatafeedRequest.g.cs | 2 +- .../Api/Ml/MlDeleteDatafeedResponse.g.cs | 2 +- .../Api/Ml/MlDeleteExpiredDataRequest.g.cs | 2 +- .../Api/Ml/MlDeleteExpiredDataResponse.g.cs | 2 +- .../Api/Ml/MlDeleteFilterRequest.g.cs | 2 +- .../Api/Ml/MlDeleteFilterResponse.g.cs | 2 +- .../Api/Ml/MlDeleteForecastRequest.g.cs | 2 +- .../Api/Ml/MlDeleteForecastResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlDeleteJobRequest.g.cs | 2 +- .../Api/Ml/MlDeleteJobResponse.g.cs | 2 +- .../Api/Ml/MlDeleteModelSnapshotRequest.g.cs | 2 +- .../Api/Ml/MlDeleteModelSnapshotResponse.g.cs | 2 +- .../Ml/MlDeleteTrainedModelAliasRequest.g.cs | 2 +- .../Ml/MlDeleteTrainedModelAliasResponse.g.cs | 2 +- .../Api/Ml/MlDeleteTrainedModelRequest.g.cs | 2 +- .../Api/Ml/MlDeleteTrainedModelResponse.g.cs | 2 +- .../Api/Ml/MlEstimateModelMemoryRequest.g.cs | 2 +- .../Api/Ml/MlEstimateModelMemoryResponse.g.cs | 2 +- .../Api/Ml/MlEvaluateDataFrameRequest.g.cs | 2 +- .../Api/Ml/MlEvaluateDataFrameResponse.g.cs | 2 +- .../MlExplainDataFrameAnalyticsRequest.g.cs | 2 +- .../MlExplainDataFrameAnalyticsResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlFlushJobRequest.g.cs | 2 +- .../_Generated/Api/Ml/MlFlushJobResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlForecastRequest.g.cs | 2 +- .../_Generated/Api/Ml/MlForecastResponse.g.cs | 2 +- .../Api/Ml/MlGetCalendarEventsRequest.g.cs | 2 +- .../Api/Ml/MlGetCalendarEventsResponse.g.cs | 2 +- .../Api/Ml/MlGetCalendarsRequest.g.cs | 2 +- .../Api/Ml/MlGetCalendarsResponse.g.cs | 2 +- .../Ml/MlGetDataFrameAnalyticsRequest.g.cs | 2 +- .../Ml/MlGetDataFrameAnalyticsResponse.g.cs | 2 +- .../MlGetDataFrameAnalyticsStatsRequest.g.cs | 2 +- .../MlGetDataFrameAnalyticsStatsResponse.g.cs | 2 +- .../Api/Ml/MlGetInfluencersRequest.g.cs | 2 +- .../Api/Ml/MlGetInfluencersResponse.g.cs | 2 +- .../Api/Ml/MlGetJobStatsRequest.g.cs | 2 +- .../Api/Ml/MlGetJobStatsResponse.g.cs | 2 +- .../Api/Ml/MlGetModelSnapshotsRequest.g.cs | 2 +- .../Api/Ml/MlGetModelSnapshotsResponse.g.cs | 2 +- .../Api/Ml/MlGetOverallBucketsRequest.g.cs | 2 +- .../Api/Ml/MlGetOverallBucketsResponse.g.cs | 2 +- .../Api/Ml/MlGetRecordsRequest.g.cs | 2 +- .../Api/Ml/MlGetRecordsResponse.g.cs | 2 +- .../Ml/MlGetTrainedModelsStatsRequest.g.cs | 2 +- .../Ml/MlGetTrainedModelsStatsResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlInfoRequest.g.cs | 2 +- .../_Generated/Api/Ml/MlInfoResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlOpenJobRequest.g.cs | 2 +- .../_Generated/Api/Ml/MlOpenJobResponse.g.cs | 2 +- .../Api/Ml/MlPostCalendarEventsRequest.g.cs | 2 +- .../Api/Ml/MlPostCalendarEventsResponse.g.cs | 2 +- .../MlPreviewDataFrameAnalyticsRequest.g.cs | 2 +- .../MlPreviewDataFrameAnalyticsResponse.g.cs | 2 +- .../Api/Ml/MlPreviewDatafeedRequest.g.cs | 2 +- .../Api/Ml/MlPreviewDatafeedResponse.g.cs | 2 +- .../Api/Ml/MlPutCalendarJobRequest.g.cs | 2 +- .../Api/Ml/MlPutCalendarJobResponse.g.cs | 2 +- .../Api/Ml/MlPutCalendarRequest.g.cs | 2 +- .../Api/Ml/MlPutCalendarResponse.g.cs | 2 +- .../Ml/MlPutDataFrameAnalyticsRequest.g.cs | 2 +- .../Ml/MlPutDataFrameAnalyticsResponse.g.cs | 2 +- .../Api/Ml/MlPutDatafeedRequest.g.cs | 2 +- .../Api/Ml/MlPutDatafeedResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlPutFilterRequest.g.cs | 2 +- .../Api/Ml/MlPutFilterResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlPutJobRequest.g.cs | 2 +- .../_Generated/Api/Ml/MlPutJobResponse.g.cs | 2 +- .../Api/Ml/MlPutTrainedModelAliasRequest.g.cs | 2 +- .../Ml/MlPutTrainedModelAliasResponse.g.cs | 2 +- .../Api/Ml/MlPutTrainedModelRequest.g.cs | 2 +- .../Api/Ml/MlPutTrainedModelResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlResetJobRequest.g.cs | 2 +- .../_Generated/Api/Ml/MlResetJobResponse.g.cs | 2 +- .../Api/Ml/MlRevertModelSnapshotRequest.g.cs | 2 +- .../Api/Ml/MlRevertModelSnapshotResponse.g.cs | 2 +- .../Api/Ml/MlSetUpgradeModeRequest.g.cs | 2 +- .../Api/Ml/MlSetUpgradeModeResponse.g.cs | 2 +- .../Ml/MlStartDataFrameAnalyticsRequest.g.cs | 2 +- .../Ml/MlStartDataFrameAnalyticsResponse.g.cs | 2 +- .../Api/Ml/MlStartDatafeedRequest.g.cs | 2 +- .../Api/Ml/MlStartDatafeedResponse.g.cs | 2 +- .../Ml/MlStopDataFrameAnalyticsRequest.g.cs | 2 +- .../Ml/MlStopDataFrameAnalyticsResponse.g.cs | 2 +- .../Api/Ml/MlStopDatafeedRequest.g.cs | 2 +- .../Api/Ml/MlStopDatafeedResponse.g.cs | 2 +- .../Ml/MlUpdateDataFrameAnalyticsRequest.g.cs | 2 +- .../MlUpdateDataFrameAnalyticsResponse.g.cs | 2 +- .../Api/Ml/MlUpdateDatafeedRequest.g.cs | 2 +- .../Api/Ml/MlUpdateDatafeedResponse.g.cs | 2 +- .../Api/Ml/MlUpdateFilterRequest.g.cs | 2 +- .../Api/Ml/MlUpdateFilterResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlUpdateJobRequest.g.cs | 2 +- .../Api/Ml/MlUpdateJobResponse.g.cs | 2 +- .../Api/Ml/MlUpdateModelSnapshotRequest.g.cs | 2 +- .../Api/Ml/MlUpdateModelSnapshotResponse.g.cs | 2 +- .../Api/Ml/MlUpgradeJobSnapshotRequest.g.cs | 2 +- .../Api/Ml/MlUpgradeJobSnapshotResponse.g.cs | 2 +- .../Api/Ml/MlValidateDetectorRequest.g.cs | 2 +- .../Api/Ml/MlValidateDetectorResponse.g.cs | 2 +- .../_Generated/Api/Ml/MlValidateRequest.g.cs | 2 +- .../_Generated/Api/Ml/MlValidateResponse.g.cs | 2 +- .../Api/Nodes/NodesHotThreadsRequest.g.cs | 2 +- .../Api/Nodes/NodesHotThreadsResponse.g.cs | 2 +- .../Api/Nodes/NodesInfoRequest.g.cs | 2 +- .../Api/Nodes/NodesInfoResponse.g.cs | 2 +- .../NodesReloadSecureSettingsRequest.g.cs | 2 +- .../NodesReloadSecureSettingsResponse.g.cs | 2 +- .../Api/Nodes/NodesStatsRequest.g.cs | 2 +- .../Api/Nodes/NodesStatsResponse.g.cs | 2 +- .../Api/Nodes/NodesUsageRequest.g.cs | 2 +- .../Api/Nodes/NodesUsageResponse.g.cs | 2 +- .../Api/OpenPointInTimeRequest.g.cs | 2 +- .../Api/OpenPointInTimeResponse.g.cs | 2 +- .../_Generated/Api/PingRequest.g.cs | 2 +- .../_Generated/Api/PingResponse.g.cs | 2 +- .../_Generated/Api/PutScriptRequest.g.cs | 2 +- .../_Generated/Api/PutScriptResponse.g.cs | 2 +- .../_Generated/Api/RankEvalRequest.g.cs | 2 +- .../_Generated/Api/RankEvalResponse.g.cs | 2 +- .../_Generated/Api/ReindexRequest.g.cs | 2 +- .../_Generated/Api/ReindexResponse.g.cs | 2 +- .../Api/ReindexRethrottleRequest.g.cs | 2 +- .../Api/ReindexRethrottleResponse.g.cs | 2 +- .../_Generated/Api/ScriptContextRequest.g.cs | 2 +- .../_Generated/Api/ScriptContextResponse.g.cs | 2 +- .../Api/ScriptLanguagesRequest.g.cs | 2 +- .../Api/ScriptLanguagesResponse.g.cs | 2 +- .../_Generated/Api/ScriptRequest.g.cs | 2 +- .../_Generated/Api/ScriptResponse.g.cs | 2 +- .../_Generated/Api/ScrollRequest.g.cs | 2 +- .../_Generated/Api/ScrollResponse.g.cs | 2 +- .../_Generated/Api/SearchRequest.g.cs | 2 +- .../_Generated/Api/SearchResponse.g.cs | 2 +- .../_Generated/Api/SearchShardsRequest.g.cs | 2 +- .../_Generated/Api/SearchShardsResponse.g.cs | 2 +- .../SearchableSnapshotsMountRequest.g.cs | 2 +- .../SearchableSnapshotsMountResponse.g.cs | 2 +- .../SearchableSnapshotsStatsRequest.g.cs | 2 +- .../SearchableSnapshotsStatsResponse.g.cs | 2 +- .../Security/SecurityAuthenticateRequest.g.cs | 2 +- .../SecurityAuthenticateResponse.g.cs | 2 +- .../SecurityChangePasswordRequest.g.cs | 2 +- .../SecurityChangePasswordResponse.g.cs | 2 +- .../SecurityClearApiKeyCacheRequest.g.cs | 2 +- .../SecurityClearApiKeyCacheResponse.g.cs | 2 +- .../SecurityClearCachedPrivilegesRequest.g.cs | 2 +- ...SecurityClearCachedPrivilegesResponse.g.cs | 2 +- .../SecurityClearCachedRealmsRequest.g.cs | 2 +- .../SecurityClearCachedRealmsResponse.g.cs | 2 +- .../SecurityClearCachedRolesRequest.g.cs | 2 +- .../SecurityClearCachedRolesResponse.g.cs | 2 +- .../Security/SecurityCreateApiKeyRequest.g.cs | 2 +- .../SecurityCreateApiKeyResponse.g.cs | 2 +- .../SecurityDeletePrivilegesRequest.g.cs | 2 +- .../SecurityDeletePrivilegesResponse.g.cs | 2 +- .../SecurityDeleteRoleMappingRequest.g.cs | 2 +- .../SecurityDeleteRoleMappingResponse.g.cs | 2 +- .../Security/SecurityDeleteRoleRequest.g.cs | 2 +- .../Security/SecurityDeleteRoleResponse.g.cs | 2 +- .../Security/SecurityDeleteUserRequest.g.cs | 2 +- .../Security/SecurityDeleteUserResponse.g.cs | 2 +- .../Security/SecurityDisableUserRequest.g.cs | 2 +- .../Security/SecurityDisableUserResponse.g.cs | 2 +- .../Security/SecurityEnableUserRequest.g.cs | 2 +- .../Security/SecurityEnableUserResponse.g.cs | 2 +- .../Security/SecurityGetApiKeyRequest.g.cs | 2 +- .../Security/SecurityGetApiKeyResponse.g.cs | 2 +- .../SecurityGetBuiltinPrivilegesRequest.g.cs | 2 +- .../SecurityGetBuiltinPrivilegesResponse.g.cs | 2 +- .../SecurityGetPrivilegesRequest.g.cs | 2 +- .../SecurityGetPrivilegesResponse.g.cs | 2 +- .../SecurityGetRoleMappingRequest.g.cs | 2 +- .../SecurityGetRoleMappingResponse.g.cs | 2 +- .../Api/Security/SecurityGetRoleRequest.g.cs | 2 +- .../Api/Security/SecurityGetRoleResponse.g.cs | 2 +- .../Api/Security/SecurityGetTokenRequest.g.cs | 2 +- .../Security/SecurityGetTokenResponse.g.cs | 2 +- .../Security/SecurityGrantApiKeyRequest.g.cs | 2 +- .../Security/SecurityGrantApiKeyResponse.g.cs | 2 +- .../SecurityHasPrivilegesRequest.g.cs | 2 +- .../SecurityHasPrivilegesResponse.g.cs | 2 +- .../SecurityInvalidateApiKeyRequest.g.cs | 2 +- .../SecurityInvalidateApiKeyResponse.g.cs | 2 +- .../SecurityInvalidateTokenRequest.g.cs | 2 +- .../SecurityInvalidateTokenResponse.g.cs | 2 +- .../Api/Security/SecurityPutUserRequest.g.cs | 2 +- .../Api/Security/SecurityPutUserResponse.g.cs | 2 +- .../Security/SecurityQueryApiKeysRequest.g.cs | 2 +- .../SecurityQueryApiKeysResponse.g.cs | 2 +- .../SecuritySamlAuthenticateRequest.g.cs | 2 +- .../SecuritySamlAuthenticateResponse.g.cs | 2 +- .../SecuritySamlCompleteLogoutRequest.g.cs | 2 +- .../SecuritySamlCompleteLogoutResponse.g.cs | 2 +- .../SecuritySamlInvalidateRequest.g.cs | 2 +- .../SecuritySamlInvalidateResponse.g.cs | 2 +- .../Security/SecuritySamlLogoutRequest.g.cs | 2 +- .../Security/SecuritySamlLogoutResponse.g.cs | 2 +- ...uritySamlPrepareAuthenticationRequest.g.cs | 2 +- ...ritySamlPrepareAuthenticationResponse.g.cs | 2 +- ...itySamlServiceProviderMetadataRequest.g.cs | 2 +- ...tySamlServiceProviderMetadataResponse.g.cs | 2 +- .../Api/Slm/SlmDeleteLifecycleRequest.g.cs | 2 +- .../Api/Slm/SlmDeleteLifecycleResponse.g.cs | 2 +- .../Api/Slm/SlmExecuteLifecycleRequest.g.cs | 2 +- .../Api/Slm/SlmExecuteLifecycleResponse.g.cs | 2 +- .../Api/Slm/SlmExecuteRetentionRequest.g.cs | 2 +- .../Api/Slm/SlmExecuteRetentionResponse.g.cs | 2 +- .../Api/Slm/SlmGetLifecycleRequest.g.cs | 2 +- .../Api/Slm/SlmGetLifecycleResponse.g.cs | 2 +- .../Api/Slm/SlmGetStatsRequest.g.cs | 2 +- .../Api/Slm/SlmGetStatsResponse.g.cs | 2 +- .../Api/Slm/SlmGetStatusRequest.g.cs | 2 +- .../Api/Slm/SlmGetStatusResponse.g.cs | 2 +- .../Api/Slm/SlmPutLifecycleRequest.g.cs | 2 +- .../Api/Slm/SlmPutLifecycleResponse.g.cs | 2 +- .../_Generated/Api/Slm/SlmStartRequest.g.cs | 2 +- .../_Generated/Api/Slm/SlmStartResponse.g.cs | 2 +- .../_Generated/Api/Slm/SlmStopRequest.g.cs | 2 +- .../_Generated/Api/Slm/SlmStopResponse.g.cs | 2 +- .../Api/Snapshot/CreateSnapshotRequest.g.cs | 2 +- .../Api/Snapshot/CreateSnapshotResponse.g.cs | 2 +- .../Api/Snapshot/DeleteSnapshotRequest.g.cs | 2 +- .../Api/Snapshot/DeleteSnapshotResponse.g.cs | 2 +- .../Api/Snapshot/GetSnapshotRequest.g.cs | 2 +- .../Api/Snapshot/GetSnapshotResponse.g.cs | 2 +- .../SnapshotCleanupRepositoryRequest.g.cs | 2 +- .../SnapshotCleanupRepositoryResponse.g.cs | 2 +- .../Api/Snapshot/SnapshotCloneRequest.g.cs | 2 +- .../Api/Snapshot/SnapshotCloneResponse.g.cs | 2 +- .../SnapshotCreateRepositoryRequest.g.cs | 2 +- .../SnapshotCreateRepositoryResponse.g.cs | 2 +- .../SnapshotDeleteRepositoryRequest.g.cs | 2 +- .../SnapshotDeleteRepositoryResponse.g.cs | 2 +- .../SnapshotGetRepositoryRequest.g.cs | 2 +- .../SnapshotGetRepositoryResponse.g.cs | 2 +- .../Api/Snapshot/SnapshotRestoreRequest.g.cs | 2 +- .../Api/Snapshot/SnapshotRestoreResponse.g.cs | 2 +- .../Api/Snapshot/SnapshotStatusRequest.g.cs | 2 +- .../Api/Snapshot/SnapshotStatusResponse.g.cs | 2 +- .../SnapshotVerifyRepositoryRequest.g.cs | 2 +- .../SnapshotVerifyRepositoryResponse.g.cs | 2 +- .../_Generated/Api/SourceRequest.g.cs | 2 +- .../_Generated/Api/SourceResponse.g.cs | 2 +- .../Api/Sql/SqlClearCursorRequest.g.cs | 2 +- .../Api/Sql/SqlClearCursorResponse.g.cs | 2 +- .../Api/Sql/SqlDeleteAsyncRequest.g.cs | 2 +- .../Api/Sql/SqlDeleteAsyncResponse.g.cs | 2 +- .../Api/Sql/SqlGetAsyncRequest.g.cs | 2 +- .../Api/Sql/SqlGetAsyncResponse.g.cs | 2 +- .../Api/Sql/SqlGetAsyncStatusRequest.g.cs | 2 +- .../Api/Sql/SqlGetAsyncStatusResponse.g.cs | 2 +- .../_Generated/Api/Sql/SqlQueryRequest.g.cs | 2 +- .../_Generated/Api/Sql/SqlQueryResponse.g.cs | 2 +- .../Api/Ssl/SslCertificatesRequest.g.cs | 2 +- .../Api/Ssl/SslCertificatesResponse.g.cs | 2 +- .../_Generated/Api/TermsEnumRequest.g.cs | 2 +- .../_Generated/Api/TermsEnumResponse.g.cs | 2 +- .../TransformDeleteTransformRequest.g.cs | 2 +- .../TransformDeleteTransformResponse.g.cs | 2 +- .../TransformGetTransformRequest.g.cs | 2 +- .../TransformGetTransformResponse.g.cs | 2 +- .../TransformGetTransformStatsRequest.g.cs | 2 +- .../TransformGetTransformStatsResponse.g.cs | 2 +- .../TransformPreviewTransformRequest.g.cs | 2 +- .../TransformPreviewTransformResponse.g.cs | 2 +- .../TransformPutTransformRequest.g.cs | 2 +- .../TransformPutTransformResponse.g.cs | 2 +- .../TransformStartTransformRequest.g.cs | 2 +- .../TransformStartTransformResponse.g.cs | 2 +- .../TransformStopTransformRequest.g.cs | 2 +- .../TransformStopTransformResponse.g.cs | 2 +- .../TransformUpdateTransformRequest.g.cs | 2 +- .../TransformUpdateTransformResponse.g.cs | 2 +- .../TransformUpgradeTransformsRequest.g.cs | 2 +- .../TransformUpgradeTransformsResponse.g.cs | 2 +- .../_Generated/Api/UpdateByQueryRequest.g.cs | 2 +- .../_Generated/Api/UpdateByQueryResponse.g.cs | 2 +- .../Api/UpdateByQueryRethrottleRequest.g.cs | 2 +- .../Api/UpdateByQueryRethrottleResponse.g.cs | 2 +- .../_Generated/Api/UpdateRequest.g.cs | 2 +- .../_Generated/Api/UpdateResponse.g.cs | 2 +- .../Api/Xpack/XpackInfoRequest.g.cs | 2 +- .../Api/Xpack/XpackInfoResponse.g.cs | 2 +- .../Api/Xpack/XpackUsageRequest.g.cs | 2 +- .../Api/Xpack/XpackUsageResponse.g.cs | 2 +- .../DataStreamNames/DataStreamNameTests.cs | 37 +- .../DataStreamNames/DataStreamNamesTests.cs | 41 +- .../IndexAlias/IndexAliasTests.cs | 69 + .../Tests/Serialization/SerializerTestBase.cs | 6 + ...onTests.DeserializesCorrectly.verified.txt | 5 + ...ionTests.SerializesCorrectly.verified.txt} | 0 ...onTests.DeserializesCorrectly.verified.txt | 10 + ...ionTests.SerializesCorrectly.verified.txt} | 0 ...onTests.DeserializesCorrectly.verified.txt | 5 + ...tionTests.SerializesCorrectly.verified.txt | 3 + 702 files changed, 3557 insertions(+), 5619 deletions(-) rename src/Elastic.Clients.Elasticsearch/Api/{ => AsyncSearch}/AsyncSearchStatusResponse.cs (100%) create mode 100644 src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/AsyncSearchSubmitRequest.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/GetAsyncSearchRequest.cs rename src/Elastic.Clients.Elasticsearch/Api/{ => AsyncSearch}/GetAsyncSearchResponse.cs (100%) delete mode 100644 src/Elastic.Clients.Elasticsearch/Api/AsyncSearchSubmitRequestDescriptor.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/BulkRequest.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/BulkResponse.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/BulkResponseItemBase.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/CountRequest.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/CreateRequest.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/DeleteRequest.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/Eql/GetEqlResponse.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/SearchRequest.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/SourceRequest.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Api/SourceResponse.cs rename src/Elastic.Clients.Elasticsearch/Api/{ => Sql}/SqlGetAsyncResponse.cs (100%) rename src/Elastic.Clients.Elasticsearch/Api/{ => Sql}/SqlQueryResponse.cs (100%) create mode 100644 src/Elastic.Clients.Elasticsearch/Api/UpdateRequestDescriptor.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient-Manual.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerAndVariantBase.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerVariantBase.cs rename src/Elastic.Clients.Elasticsearch/Common/{Infer/IndexName/IndexAlias.cs => Containers/IContainer.cs} (55%) create mode 100644 src/Elastic.Clients.Elasticsearch/Common/Containers/IContainerVariant.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Common/Containers/VariantDescriptorBase.cs delete mode 100644 src/Elastic.Clients.Elasticsearch/Common/ForAttribute.cs delete mode 100644 src/Elastic.Clients.Elasticsearch/Common/Infer/IndexUuid/IndexUuid.cs delete mode 100644 src/Elastic.Clients.Elasticsearch/Common/Infer/Name/Name.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Common/ReadOnlyIndexNameDictionary.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Common/Request/PlainRequestBase.cs delete mode 100644 src/Elastic.Clients.Elasticsearch/Common/TaggedUnion.cs delete mode 100644 src/Elastic.Clients.Elasticsearch/Common/TextToAnalyze.cs rename src/Elastic.Clients.Elasticsearch/Common/{ => UrlParameters}/DataStreamNames/DataStreamName.cs (100%) rename src/Elastic.Clients.Elasticsearch/Common/{ => UrlParameters}/DataStreamNames/DataStreamNames.cs (100%) create mode 100644 src/Elastic.Clients.Elasticsearch/Common/UrlParameters/IndexAlias/IndexAlias.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Common/UrlParameters/IndexUuid/IndexUuid.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Common/UrlParameters/Name/Name.cs rename src/Elastic.Clients.Elasticsearch/Common/{Infer => UrlParameters}/Name/Names.cs (97%) rename src/Elastic.Clients.Elasticsearch/Common/{Infer/NodeId => UrlParameters/NodeIds}/NodeIds.cs (96%) rename src/Elastic.Clients.Elasticsearch/Common/{Infer => UrlParameters}/TaskId/TaskId.cs (84%) create mode 100644 src/Elastic.Clients.Elasticsearch/Common/UrlParameters/Username/Username.cs delete mode 100644 src/Elastic.Clients.Elasticsearch/FutureGenerated/CommonOptions/TimeUnit/Time.cs delete mode 100644 src/Elastic.Clients.Elasticsearch/FutureGenerated/DesignPrototype.cs create mode 100644 src/Elastic.Clients.Elasticsearch/FutureGenerated/FieldType.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/FieldNameQueryAttribute.cs rename src/Elastic.Clients.Elasticsearch/{Common/Infer/RelationName/RelationNameExtensions.cs => Serialization/IDictionaryKey.cs} (55%) rename src/Elastic.Clients.Elasticsearch/Serialization/{JsonWriter.cs => ISourceMarker.cs} (85%) create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/IStreamSerializable.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/IgnoreAttribute.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/InterfaceConverterAttribute.cs rename src/Elastic.Clients.Elasticsearch/Serialization/{ConvertAsAttribute.cs => InterfaceConverterFactory.cs} (50%) create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/IntermediateConverter.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/IntermediateSourceConverter.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/ReadOnlyIndexNameDictionaryConverter.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/ReadOnlyIndexNameDictionaryConverterFactory.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/ResolvableDictionaryFormatterFactory.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/SelfSerializable.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/SerializationConstants.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/SimpleInterfaceConverter.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/SourceConverter.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/SourceConverterAttribute.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/SourceConverterFactory.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/SourceMarker.cs delete mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/StatefulSerializerExtensions.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/StringEnumAttribute.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Serialization/TermsAggregateSerializationHelper.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregateDictionary.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregationContainer.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Aggregations/AggregationContainerDescriptor.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Aggregations/EmptyTermsAggregate.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Aggregations/EmptyTermsBucket.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Aggregations/MultiBucketAggregateBase.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Aggregations/TermsAggregate.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Aggregations/TermsBucket.cs rename src/Elastic.Clients.Elasticsearch/{Api => Types/AsyncSearch}/AsyncSearch.cs (100%) create mode 100644 src/Elastic.Clients.Elasticsearch/Types/OpType.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/PointInTimeReferenceDescriptor.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/QueryDsl/QueryContainerDescriptor.cs rename src/Elastic.Clients.Elasticsearch/{FutureGenerated/CommonOptions/Range => Types}/Ranges.cs (100%) create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Refresh.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Scripting/InlineScript.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Scripting/InlineScriptDescriptor.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/Scripting/ScriptDescriptor.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/SourceConfig.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/StoredScriptId.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/TermsOrder.cs create mode 100644 src/Elastic.Clients.Elasticsearch/Types/WaitForActiveShards.cs rename tests/Tests/Common/{ => UrlParameters}/DataStreamNames/DataStreamNameTests.cs (74%) rename tests/Tests/Common/{ => UrlParameters}/DataStreamNames/DataStreamNamesTests.cs (82%) create mode 100644 tests/Tests/Common/UrlParameters/IndexAlias/IndexAliasTests.cs create mode 100644 tests/Tests/_VerifySnapshots/DataStreamNameSerializationTests.DeserializesCorrectly.verified.txt rename tests/Tests/_VerifySnapshots/{DataStreamNameTests.DataStreamName_SerialisationTest.verified.txt => DataStreamNameSerializationTests.SerializesCorrectly.verified.txt} (100%) create mode 100644 tests/Tests/_VerifySnapshots/DataStreamNamesSerializationTests.DeserializesCorrectly.verified.txt rename tests/Tests/_VerifySnapshots/{DataStreamNamesTests.DataStreamNames_SerialisationTest.verified.txt => DataStreamNamesSerializationTests.SerializesCorrectly.verified.txt} (100%) create mode 100644 tests/Tests/_VerifySnapshots/IndexAliasSerializationTests.DeserializesCorrectly.verified.txt create mode 100644 tests/Tests/_VerifySnapshots/IndexAliasSerializationTests.SerializesCorrectly.verified.txt diff --git a/src/Elastic.Clients.Elasticsearch/Api/AsyncSearchStatusResponse.cs b/src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/AsyncSearchStatusResponse.cs similarity index 100% rename from src/Elastic.Clients.Elasticsearch/Api/AsyncSearchStatusResponse.cs rename to src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/AsyncSearchStatusResponse.cs diff --git a/src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/AsyncSearchSubmitRequest.cs b/src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/AsyncSearchSubmitRequest.cs new file mode 100644 index 00000000000..b8d5cbfec9c --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/AsyncSearchSubmitRequest.cs @@ -0,0 +1,33 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; +using Elastic.Clients.Elasticsearch.QueryDsl; + +namespace Elastic.Clients.Elasticsearch.AsyncSearch +{ + public partial class AsyncSearchSubmitRequest + { + // Any request may contain aggregations so we force typed_keys in order to successfully deserialise them. + internal override void BeforeRequest() => TypedKeys = true; + } + + public sealed partial class AsyncSearchSubmitRequestDescriptor + { + public AsyncSearchSubmitRequestDescriptor MatchAll(Action? selector = null) => selector is null ? Query(q => q.MatchAll()) : Query(q => q.MatchAll(selector)); + + internal override void BeforeRequest() => TypedKeys(true); + } + + public sealed partial class AsyncSearchSubmitRequestDescriptor + { + public AsyncSearchSubmitRequestDescriptor MatchAll() + { + Query(new MatchAllQuery()); + return Self; + } + + internal override void BeforeRequest() => TypedKeys(true); + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/GetAsyncSearchRequest.cs b/src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/GetAsyncSearchRequest.cs new file mode 100644 index 00000000000..4979aace729 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/GetAsyncSearchRequest.cs @@ -0,0 +1,24 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +namespace Elastic.Clients.Elasticsearch.AsyncSearch +{ + public partial class GetAsyncSearchRequest + { + // Any request may contain aggregations so we force typed_keys in order to successfully deserialise them. + internal override void BeforeRequest() => TypedKeys = true; + } + + public sealed partial class GetAsyncSearchRequestDescriptor + { + // Any request may contain aggregations so we force typed_keys in order to successfully deserialise them. + internal override void BeforeRequest() => TypedKeys(true); + } + + public sealed partial class GetAsyncSearchRequestDescriptor + { + // Any request may contain aggregations so we force typed_keys in order to successfully deserialise them. + internal override void BeforeRequest() => TypedKeys(true); + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/GetAsyncSearchResponse.cs b/src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/GetAsyncSearchResponse.cs similarity index 100% rename from src/Elastic.Clients.Elasticsearch/Api/GetAsyncSearchResponse.cs rename to src/Elastic.Clients.Elasticsearch/Api/AsyncSearch/GetAsyncSearchResponse.cs diff --git a/src/Elastic.Clients.Elasticsearch/Api/AsyncSearchSubmitRequestDescriptor.cs b/src/Elastic.Clients.Elasticsearch/Api/AsyncSearchSubmitRequestDescriptor.cs deleted file mode 100644 index 414f4855be3..00000000000 --- a/src/Elastic.Clients.Elasticsearch/Api/AsyncSearchSubmitRequestDescriptor.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to Elasticsearch B.V under one or more agreements. -// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -using System; -using Elastic.Clients.Elasticsearch.QueryDsl; - -namespace Elastic.Clients.Elasticsearch.AsyncSearch; - -public sealed partial class AsyncSearchSubmitRequestDescriptor -{ - public AsyncSearchSubmitRequestDescriptor MatchAll(Action? selector = null) => selector is null ? Query(q => q.MatchAll()) : Query(q => q.MatchAll(selector)); -} diff --git a/src/Elastic.Clients.Elasticsearch/Api/BulkRequest.cs b/src/Elastic.Clients.Elasticsearch/Api/BulkRequest.cs new file mode 100644 index 00000000000..40425b6d939 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/BulkRequest.cs @@ -0,0 +1,256 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; +using System.Threading.Tasks; +using Elastic.Transport; +using System.IO; +using System.Collections.Generic; +using System.Linq; + +namespace Elastic.Clients.Elasticsearch +{ + public partial class BulkRequest : IStreamSerializable + { + protected IRequest Self => this; + + public BulkOperationsCollection Operations { get; set; } + + protected override string ContentType => "application/x-ndjson"; + + protected override string Accept => "application/json"; + + public void Serialize(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting = SerializationFormatting.None) + { + if (Operations is null) + return; + + var index = Self.RouteValues.Get("index"); + + foreach (var op in Operations) + { + if (op is not IStreamSerializable serializable) + throw new InvalidOperationException(""); + + op.PrepareIndex(index); + + serializable.Serialize(stream, settings, formatting); + stream.WriteByte((byte)'\n'); + } + } + + public async Task SerializeAsync(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting = SerializationFormatting.None) + { + if (Operations is null) + return; + + var index = Self.RouteValues.Get("index"); + + foreach (var op in Operations) + { + if (op is not IStreamSerializable serializable) + throw new InvalidOperationException(""); + + op.PrepareIndex(index); + + await serializable.SerializeAsync(stream, settings, formatting).ConfigureAwait(false); + stream.WriteByte((byte)'\n'); + } + } + } + + public sealed partial class BulkRequestDescriptor : IStreamSerializable + { + protected override string ContentType => "application/x-ndjson"; + + protected override string Accept => "application/json"; + + private readonly BulkOperationsCollection _operations = new(); + + public BulkRequestDescriptor Index(string index) + { + RouteValues.Optional("index", IndexName.Parse(index)); + return Self; + } + + public BulkRequestDescriptor Create(TSource document, Action> configure = null) + { + var descriptor = new BulkCreateOperationDescriptor(document); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Create(TSource document, IndexName index, Action> configure = null) + { + var descriptor = new BulkCreateOperationDescriptor(document, index); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Index(TSource document, Action> configure = null) + { + var descriptor = new BulkIndexOperationDescriptor(document); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Index(TSource document, IndexName index, Action> configure = null) + { + var descriptor = new BulkIndexOperationDescriptor(document, index); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Update(BulkUpdateOperationBase update) + { + _operations.Add(update); + return this; + } + + public BulkRequestDescriptor Update(Action> configure) + { + var descriptor = new BulkUpdateOperationDescriptor(); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Update(Action> configure) => + Update(configure); + + public BulkRequestDescriptor Delete(Id id, Action configure = null) + { + var descriptor = new BulkDeleteOperationDescriptor(id); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Delete(string id, Action configure = null) + { + var descriptor = new BulkDeleteOperationDescriptor(id); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Delete(Action configure) + { + var descriptor = new BulkDeleteOperationDescriptor(); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Delete(TSource documentToDelete, Action configure = null) + { + var descriptor = new BulkDeleteOperationDescriptor(new Id(documentToDelete)); + configure?.Invoke(descriptor); + _operations.Add(descriptor); + return this; + } + + public BulkRequestDescriptor Delete(Action configure) => Delete(configure); + + public BulkRequestDescriptor CreateMany(IEnumerable documents, Action, TSource> bulkCreateSelector) => + AddOperations(documents, bulkCreateSelector, o => new BulkCreateOperationDescriptor(o)); + + public BulkRequestDescriptor CreateMany(IEnumerable documents) => + AddOperations(documents, null, o => new BulkCreateOperationDescriptor(o)); + + public BulkRequestDescriptor IndexMany(IEnumerable documents, Action, TSource> bulkIndexSelector) => + AddOperations(documents, bulkIndexSelector, o => new BulkIndexOperationDescriptor(o)); + + public BulkRequestDescriptor IndexMany(IEnumerable documents) => + AddOperations(documents, null, o => new BulkIndexOperationDescriptor(o)); + + public BulkRequestDescriptor UpdateMany(IEnumerable objects, Action, TSource> bulkIndexSelector) => + AddOperations(objects, bulkIndexSelector, o => new BulkUpdateOperationDescriptor().IdFrom(o)); + + public BulkRequestDescriptor UpdateMany(IEnumerable objects) => + AddOperations(objects, null, o => new BulkUpdateOperationDescriptor().IdFrom(o)); + + public BulkRequestDescriptor DeleteMany(IEnumerable objects, Action bulkDeleteSelector) => + AddOperations(objects, bulkDeleteSelector, obj => new BulkDeleteOperationDescriptor(new Id(obj))); + + public BulkRequestDescriptor DeleteMany(IEnumerable ids, Action bulkDeleteSelector) => + AddOperations(ids, bulkDeleteSelector, id => new BulkDeleteOperationDescriptor(id)); + + public BulkRequestDescriptor DeleteMany(IEnumerable objects) => + AddOperations(objects, null, obj => new BulkDeleteOperationDescriptor(obj)); + + public BulkRequestDescriptor DeleteMany(IndexName index, IEnumerable ids) => + AddOperations(ids, null, id => new BulkDeleteOperationDescriptor(id).Index(index)); + + public void Serialize(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting = SerializationFormatting.None) + { + if (_operations is null) + return; + + var index = Self.RouteValues.Get("index"); + + foreach (var op in _operations) + { + if (op is not IStreamSerializable serializable) + throw new InvalidOperationException(""); + + op.PrepareIndex(index); + + serializable.Serialize(stream, settings, formatting); + stream.WriteByte((byte)'\n'); + } + } + + public async Task SerializeAsync(Stream stream, IElasticsearchClientSettings settings, SerializationFormatting formatting = SerializationFormatting.None) + { + if (_operations is null) + return; + + var index = Self.RouteValues.Get("index"); + + foreach (var op in _operations) + { + if (op is not IStreamSerializable serializable) + throw new InvalidOperationException(""); + + op.PrepareIndex(index); + + await serializable.SerializeAsync(stream, settings, formatting).ConfigureAwait(false); + stream.WriteByte((byte)'\n'); + } + } + + private BulkRequestDescriptor AddOperations( + IEnumerable objects, + Action configureDescriptor, + Func createDescriptor + ) where TDescriptor : IBulkOperation + { + if (@objects == null) + return this; + + var objectsList = @objects.ToList(); + var operations = new List(objectsList.Count()); + + foreach (var o in objectsList) + { + var descriptor = createDescriptor(o); + + if (configureDescriptor is not null) + { + configureDescriptor(descriptor, o); + } + + operations.Add(descriptor); + } + + _operations.AddRange(operations); + return Self; + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/BulkResponse.cs b/src/Elastic.Clients.Elasticsearch/Api/BulkResponse.cs new file mode 100644 index 00000000000..ca405bf7495 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/BulkResponse.cs @@ -0,0 +1,34 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Text.Json.Serialization; +using System.Text; +using System.Linq; + +namespace Elastic.Clients.Elasticsearch +{ + public partial class BulkResponse + { + [JsonConverter(typeof(BulkResponseItemConverter)), JsonPropertyName("items")] + public IReadOnlyList Items { get; init; } + + [JsonIgnore] + public IEnumerable ItemsWithErrors => !Items.HasAny() + ? Enumerable.Empty() + : Items.Where(i => !i.IsValid); + + public override bool IsValid => base.IsValid && !Errors && !ItemsWithErrors.HasAny(); + + protected override void DebugIsValid(StringBuilder sb) + { + if (Items == null) + return; + + sb.AppendLine($"# Invalid Bulk items:"); + foreach (var i in Items.Select((item, i) => new { item, i }).Where(i => !i.item.IsValid)) + sb.AppendLine($" operation[{i.i}]: {i.item}"); + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/BulkResponseItemBase.cs b/src/Elastic.Clients.Elasticsearch/Api/BulkResponseItemBase.cs new file mode 100644 index 00000000000..2ed4a565961 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/BulkResponseItemBase.cs @@ -0,0 +1,27 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +namespace Elastic.Clients.Elasticsearch +{ + public abstract partial class BulkResponseItemBase + { + public abstract string Operation { get; } + + public bool IsValid + { + get + { + if (Error is not null) + return false; + + return Operation.ToLowerInvariant() switch + { + "delete" => Status == 200 || Status == 404, + "update" or "index" or "create" => Status == 200 || Status == 201, + _ => false, + }; + } + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/CountRequest.cs b/src/Elastic.Clients.Elasticsearch/Api/CountRequest.cs new file mode 100644 index 00000000000..6c34cf2a24e --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/CountRequest.cs @@ -0,0 +1,41 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; +using Elastic.Clients.Elasticsearch.QueryDsl; + +namespace Elastic.Clients.Elasticsearch +{ + public partial class CountRequest : CountRequest + { + //protected CountRequest TypedSelf => this; + + ////{index}/_count + public CountRequest() : base(typeof(TDocument)) + { + } + + ////{index}/_count + ///Optional, accepts null + public CountRequest(Indices index) : base(index) + { + } + } + + public partial class CountRequestDescriptor + { + public CountRequestDescriptor Index(Indices indices) + { + RouteValues.Optional("index", indices); + return Self; + } + + public CountRequestDescriptor Query(Func configure) + { + var container = configure?.Invoke(new QueryContainerDescriptor()); + QueryValue = container; + return Self; + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/CreateRequest.cs b/src/Elastic.Clients.Elasticsearch/Api/CreateRequest.cs new file mode 100644 index 00000000000..27fc2f5a550 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/CreateRequest.cs @@ -0,0 +1,23 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using Elastic.Transport; +using System.Text.Json; + +namespace Elastic.Clients.Elasticsearch +{ + public sealed partial class CreateRequest : ICustomJsonWriter + { + + public CreateRequest(Id id) : this(typeof(TDocument), id) + { + } + + public CreateRequest(TDocument documentWithId, IndexName index = null, Id id = null) + : this(index ?? typeof(TDocument), id ?? Id.From(documentWithId)) => + Document = documentWithId; + + public void WriteJson(Utf8JsonWriter writer, Serializer sourceSerializer) => SourceSerialisation.Serialize(Document, writer, sourceSerializer); + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/DeleteRequest.cs b/src/Elastic.Clients.Elasticsearch/Api/DeleteRequest.cs new file mode 100644 index 00000000000..43d0131d409 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/DeleteRequest.cs @@ -0,0 +1,17 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +namespace Elastic.Clients.Elasticsearch +{ + public sealed partial class DeleteRequest : DeleteRequest + { + public DeleteRequest(IndexName index, Id id) : base(index, id) { } + + public DeleteRequest(Id id) : this(typeof(TDocument), id) + { + } + + public DeleteRequest(TDocument documentWithId, IndexName index = null, Id id = null) : this(index ?? typeof(TDocument), id ?? Id.From(documentWithId)) { } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/Eql/GetEqlResponse.cs b/src/Elastic.Clients.Elasticsearch/Api/Eql/GetEqlResponse.cs new file mode 100644 index 00000000000..47e18383248 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/Eql/GetEqlResponse.cs @@ -0,0 +1,27 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Elastic.Clients.Elasticsearch.Eql +{ + public partial class GetEqlResponse + { + private IReadOnlyCollection> _events; + private IReadOnlyCollection> _sequences; + + + [JsonIgnore] + public IReadOnlyCollection> Events => + _events ??= Hits?.Events ?? EmptyReadOnly>.Collection; + + [JsonIgnore] + public IReadOnlyCollection> Sequences => + _sequences ??= Hits?.Sequences ?? EmptyReadOnly>.Collection; + + [JsonIgnore] + public long Total => Hits?.Total.Value ?? -1; + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/SearchRequest.cs b/src/Elastic.Clients.Elasticsearch/Api/SearchRequest.cs new file mode 100644 index 00000000000..cb1edd64b82 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/SearchRequest.cs @@ -0,0 +1,72 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Elastic.Clients.Elasticsearch +{ + public partial class SearchRequest + { + internal override void BeforeRequest() + { + if (Aggregations is not null) + { + TypedKeys = true; + } + } + + protected override string ResolveUrl(RouteValues routeValues, IElasticsearchClientSettings settings) + { + if (Pit is not null && !string.IsNullOrEmpty(Pit.Id ?? string.Empty) && routeValues.ContainsKey("index")) + { + routeValues.Remove("index"); + } + + return base.ResolveUrl(routeValues, settings); + } + } + + public partial class SearchRequest + { + public SearchRequest(Indices? indices) : base(indices) + { + } + } + + public sealed partial class SearchRequestDescriptor + { + public SearchRequestDescriptor Index(Indices indices) + { + Self.RouteValues.Optional("index", indices); + return Self; + } + + public SearchRequestDescriptor Pit(string id, Action configure) + { + PitValue = null; + PitDescriptorAction = null; + configure += a => a.Id(id); + PitDescriptorAction = configure; + return Self; + } + + internal override void BeforeRequest() + { + if (AggregationsValue is not null || AggregationsDescriptor is not null || AggregationsDescriptorAction is not null) + { + TypedKeys(true); + } + } + + protected override string ResolveUrl(RouteValues routeValues, IElasticsearchClientSettings settings) + { + if ((Self.PitValue is not null || Self.PitDescriptor is not null || Self.PitDescriptorAction is not null) && routeValues.ContainsKey("index")) + { + routeValues.Remove("index"); + } + + return base.ResolveUrl(routeValues, settings); + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/SourceRequest.cs b/src/Elastic.Clients.Elasticsearch/Api/SourceRequest.cs new file mode 100644 index 00000000000..3f34a52e8d0 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/SourceRequest.cs @@ -0,0 +1,24 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +namespace Elastic.Clients.Elasticsearch +{ + // TODO - Should be added as a rule to the descriptor generator + //public sealed partial class SourceRequestDescriptor + //{ + // public SourceRequestDescriptor(TDocument documentWithId, IndexName index = null, Id id = null) : this(index ?? typeof(TDocument), id ?? Id.From(documentWithId)) => Doc + //} + + public partial class SourceRequestDescriptor + { + /// + /// A shortcut into calling Index(typeof(TOther)). + /// + public SourceRequestDescriptor Index() + { + RouteValues.Required("index", (IndexName)typeof(TOther)); + return Self; + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/SourceResponse.cs b/src/Elastic.Clients.Elasticsearch/Api/SourceResponse.cs new file mode 100644 index 00000000000..09b6d82f5a1 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/SourceResponse.cs @@ -0,0 +1,30 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System.Text.Json; +using System.IO; + +namespace Elastic.Clients.Elasticsearch +{ + public partial class SourceResponse : ISelfDeserializable + { + public TDocument Body { get; set; } + + public void Deserialize(ref Utf8JsonReader reader, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + using var jsonDoc = JsonSerializer.Deserialize(ref reader); + + using var stream = new MemoryStream(); + + var writer = new Utf8JsonWriter(stream); + jsonDoc.WriteTo(writer); + writer.Flush(); + stream.Position = 0; + + var body = settings.SourceSerializer.Deserialize(stream); + + Body = body; + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Api/SqlGetAsyncResponse.cs b/src/Elastic.Clients.Elasticsearch/Api/Sql/SqlGetAsyncResponse.cs similarity index 100% rename from src/Elastic.Clients.Elasticsearch/Api/SqlGetAsyncResponse.cs rename to src/Elastic.Clients.Elasticsearch/Api/Sql/SqlGetAsyncResponse.cs diff --git a/src/Elastic.Clients.Elasticsearch/Api/SqlQueryResponse.cs b/src/Elastic.Clients.Elasticsearch/Api/Sql/SqlQueryResponse.cs similarity index 100% rename from src/Elastic.Clients.Elasticsearch/Api/SqlQueryResponse.cs rename to src/Elastic.Clients.Elasticsearch/Api/Sql/SqlQueryResponse.cs diff --git a/src/Elastic.Clients.Elasticsearch/Api/UpdateRequestDescriptor.cs b/src/Elastic.Clients.Elasticsearch/Api/UpdateRequestDescriptor.cs new file mode 100644 index 00000000000..ee03d57d08c --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Api/UpdateRequestDescriptor.cs @@ -0,0 +1,17 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +namespace Elastic.Clients.Elasticsearch +{ + public sealed partial class UpdateRequestDescriptor + { + public UpdateRequestDescriptor Document(TDocument document) + { + DocumentValue = document; + return Self; + } + + public UpdateRequestDescriptor PartialDocument(TPartialDocument document) => this; + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient-BulkAll.cs b/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient-BulkAll.cs index 981ad3a0cae..30d3d10131e 100644 --- a/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient-BulkAll.cs +++ b/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient-BulkAll.cs @@ -11,8 +11,6 @@ namespace Elastic.Clients.Elasticsearch; public partial class ElasticsearchClient { - //public HelpersNamespace Helpers { get; private set; } - public BulkAllObservable BulkAll(IEnumerable documents, Action> configure, CancellationToken cancellationToken = default) { var descriptor = new BulkAllRequestDescriptor(documents); @@ -23,20 +21,3 @@ public BulkAllObservable BulkAll(IEnumerable documents, Action BulkAll(IBulkAllRequest request, CancellationToken cancellationToken = default) => new(this, request, cancellationToken); } - -//public class HelpersNamespace : NamespacedClientProxy -//{ -// private readonly ElasticsearchClient _client; - -// internal HelpersNamespace(ElasticsearchClient client) : base(client) => _client = client; - -// public BulkAllObservable BulkAllObservable(IEnumerable documents, Action> configure, CancellationToken cancellationToken = default) -// { -// var descriptor = new BulkAllRequestDescriptor(documents); -// configure?.Invoke(descriptor); -// return BulkAllObservable(descriptor, cancellationToken); -// } - -// public BulkAllObservable BulkAllObservable(IBulkAllRequest request, CancellationToken cancellationToken = default) => -// new(_client, request, cancellationToken); -//} diff --git a/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient-Manual.cs b/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient-Manual.cs new file mode 100644 index 00000000000..86eb07c0ce9 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient-Manual.cs @@ -0,0 +1,92 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; +using System.Threading.Tasks; +using System.Threading; + +namespace Elastic.Clients.Elasticsearch +{ + public partial class ElasticsearchClient + { + public IndexResponse Index(TDocument document, Action> configureRequest) + { + var descriptor = new IndexRequestDescriptor(documentWithId: document); + configureRequest?.Invoke(descriptor); + return DoRequest, IndexResponse>(descriptor); + } + + public Task IndexAsync(TDocument document, Action> configureRequest, CancellationToken cancellationToken = default) + { + var descriptor = new IndexRequestDescriptor(documentWithId: document); + configureRequest?.Invoke(descriptor); + return DoRequestAsync, IndexResponse>(descriptor); + } + + public CreateResponse Create(TDocument document, Action> configureRequest) + { + var descriptor = new CreateRequestDescriptor(document); + configureRequest?.Invoke(descriptor); + return DoRequest, CreateResponse>(descriptor); + } + + public Task CreateAsync(TDocument document, Action> configureRequest, CancellationToken cancellationToken = default) + { + var descriptor = new CreateRequestDescriptor(document); + configureRequest?.Invoke(descriptor); + return DoRequestAsync, CreateResponse>(descriptor); + } + + public DeleteResponse Delete(Id id, Action> configureRequest) + { + var descriptor = new DeleteRequestDescriptor(id); + configureRequest?.Invoke(descriptor); + return DoRequest, DeleteResponse>(descriptor); + } + + public Task DeleteAsync(Id id, Action> configureRequest, CancellationToken cancellationToken = default) + { + var descriptor = new DeleteRequestDescriptor(id); + configureRequest?.Invoke(descriptor); + return DoRequestAsync, DeleteResponse>(descriptor); + } + + public Task> UpdateAsync(IndexName index, Id id, Action> configureRequest = null, CancellationToken cancellationToken = default) + { + var descriptor = new UpdateRequestDescriptor(index, id); + configureRequest?.Invoke(descriptor); + return DoRequestAsync, UpdateResponse>(descriptor); + } + + public UpdateResponse Update(IndexName index, Id id, Action> configureRequest = null) + { + var descriptor = new UpdateRequestDescriptor(index, id); + configureRequest?.Invoke(descriptor); + return DoRequest, UpdateResponse>(descriptor); + } + + public SourceResponse Source(DocumentPath id, Action> configureRequest = null) + { + var descriptor = new SourceRequestDescriptor(document: id.Document, index: id?.Self?.Index ?? typeof(TDocument), id: id?.Self?.Id ?? Id.From(id.Document)); + configureRequest?.Invoke(descriptor); + return DoRequest, SourceResponse>(descriptor); + } + + public CountResponse Count(Action> configureRequest = null) + { + var descriptor = new CountRequestDescriptor(); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequest, CountResponse>(descriptor); + } + + public Task CountAsync(Action> configureRequest = null, CancellationToken cancellationToken = default) + { + var descriptor = new CountRequestDescriptor(); + configureRequest?.Invoke(descriptor); + descriptor.BeforeRequest(); + return DoRequestAsync, CountResponse>(descriptor); + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs b/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs index 9fa42bd8394..5e957e0b0bf 100644 --- a/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs +++ b/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs @@ -11,7 +11,7 @@ namespace Elastic.Clients.Elasticsearch; /// -public partial class ElasticsearchClient +public sealed partial class ElasticsearchClient { private readonly ITransport _transport; diff --git a/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationBase.cs b/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationBase.cs index f11bacd2eb8..dc34f382b84 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationBase.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationBase.cs @@ -9,7 +9,7 @@ namespace Elastic.Clients.Elasticsearch.Aggregations; public abstract class AggregationBase { - protected AggregationBase(string name) => Name = name; + internal AggregationBase(string name) => Name = name; /// /// Custom metadata associated with the aggregation. diff --git a/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationCombinator.cs b/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationCombinator.cs index d74a5107d12..50974da236b 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationCombinator.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationCombinator.cs @@ -8,7 +8,7 @@ namespace Elastic.Clients.Elasticsearch.Aggregations; /// -/// Combines aggregations into a single list of aggregations +/// Combines aggregations into a single list of aggregations. /// internal class AggregationCombinator : AggregationBase { diff --git a/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationDictionary.cs b/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationDictionary.cs index 4fb8fcd162d..276fdfe054e 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationDictionary.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Aggregations/AggregationDictionary.cs @@ -11,7 +11,7 @@ namespace Elastic.Clients.Elasticsearch.Aggregations; /// /// Describes aggregations that we would like to execute on Elasticsearch. /// -public class AggregationDictionary : IsADictionaryBase +public sealed class AggregationDictionary : IsADictionaryBase { public AggregationDictionary() { } diff --git a/src/Elastic.Clients.Elasticsearch/Common/Configuration/ClrPropertyMapping.cs b/src/Elastic.Clients.Elasticsearch/Common/Configuration/ClrPropertyMapping.cs index a3fa8bb43ed..231b22a61dd 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Configuration/ClrPropertyMapping.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Configuration/ClrPropertyMapping.cs @@ -5,43 +5,42 @@ using System; using System.Linq.Expressions; -namespace Elastic.Clients.Elasticsearch +namespace Elastic.Clients.Elasticsearch; + +public abstract class ClrPropertyMappingBase : IClrPropertyMapping + where TDocument : class { - public abstract class ClrPropertyMappingBase : IClrPropertyMapping - where TDocument : class - { - protected ClrPropertyMappingBase(Expression> property) => Self.Property = property; + internal ClrPropertyMappingBase(Expression> property) => Self.Property = property; - protected IClrPropertyMapping Self => this; - bool IClrPropertyMapping.Ignore { get; set; } - string IClrPropertyMapping.NewName { get; set; } - Expression> IClrPropertyMapping.Property { get; set; } + protected IClrPropertyMapping Self => this; + bool IClrPropertyMapping.Ignore { get; set; } + string IClrPropertyMapping.NewName { get; set; } + Expression> IClrPropertyMapping.Property { get; set; } - IPropertyMapping IClrPropertyMapping.ToPropertyMapping() => Self.Ignore - ? PropertyMapping.Ignored - : new PropertyMapping { Name = Self.NewName }; - } + IPropertyMapping IClrPropertyMapping.ToPropertyMapping() => Self.Ignore + ? PropertyMapping.Ignored + : new PropertyMapping { Name = Self.NewName }; +} - public interface IClrPropertyMapping where TDocument : class - { - bool Ignore { get; set; } - string NewName { get; set; } - Expression> Property { get; set; } +public interface IClrPropertyMapping where TDocument : class +{ + bool Ignore { get; set; } + string NewName { get; set; } + Expression> Property { get; set; } - IPropertyMapping ToPropertyMapping(); - } + IPropertyMapping ToPropertyMapping(); +} - public class IgnoreClrPropertyMapping : ClrPropertyMappingBase where TDocument : class - { - public IgnoreClrPropertyMapping(Expression> property) : base(property) => Self.Ignore = true; - } +public class IgnoreClrPropertyMapping : ClrPropertyMappingBase where TDocument : class +{ + public IgnoreClrPropertyMapping(Expression> property) : base(property) => Self.Ignore = true; +} - public class RenameClrPropertyMapping : ClrPropertyMappingBase where TDocument : class +public class RenameClrPropertyMapping : ClrPropertyMappingBase where TDocument : class +{ + public RenameClrPropertyMapping(Expression> property, string newName) : base(property) { - public RenameClrPropertyMapping(Expression> property, string newName) : base(property) - { - newName.ThrowIfNull(nameof(newName)); - Self.NewName = newName; - } + newName.ThrowIfNull(nameof(newName)); + Self.NewName = newName; } } diff --git a/src/Elastic.Clients.Elasticsearch/Common/Configuration/MemberInfoResolver.cs b/src/Elastic.Clients.Elasticsearch/Common/Configuration/MemberInfoResolver.cs index e8123c7c08f..b3bf64edc09 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Configuration/MemberInfoResolver.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Configuration/MemberInfoResolver.cs @@ -11,7 +11,7 @@ namespace Elastic.Clients.Elasticsearch /// /// Resolves member infos in an expression, instance may NOT be shared. /// - public class MemberInfoResolver : ExpressionVisitor + public sealed class MemberInfoResolver : ExpressionVisitor { // ReSharper disable once VirtualMemberCallInConstructor public MemberInfoResolver(Expression expression) => Visit(expression); diff --git a/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerAndVariantBase.cs b/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerAndVariantBase.cs new file mode 100644 index 00000000000..9f2ebc52179 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerAndVariantBase.cs @@ -0,0 +1,14 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Elastic.Clients.Elasticsearch; + +public abstract class ContainerAndVariantBase : ContainerVariantBase, IContainer where TVariantContainer : IContainer +{ + internal ContainerVariantBase Variant { get; } + + public ContainerAndVariantBase(ContainerVariantBase variant) => Variant = variant ?? throw new ArgumentNullException(nameof(variant)); +} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerBase.cs b/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerBase.cs index 2f2d259b10e..da8401e6d13 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerBase.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerBase.cs @@ -3,132 +3,12 @@ // See the LICENSE file in the project root for more information. using System; -using System.Text.Json.Serialization; namespace Elastic.Clients.Elasticsearch; -public interface IContainer -{ -} - public abstract class ContainerBase : IContainer { internal ContainerVariantBase Variant { get; } - public ContainerBase(ContainerVariantBase variant) => Variant = variant ?? throw new ArgumentNullException(nameof(variant)); -} - -public abstract class ContainerAndVariantBase : ContainerVariantBase, IContainer where TVariantContainer : IContainer -{ - internal ContainerVariantBase Variant { get; } - - public ContainerAndVariantBase(ContainerVariantBase variant) => Variant = variant ?? throw new ArgumentNullException(nameof(variant)); -} - -public abstract class ContainerVariantBase -{ - [JsonIgnore] - internal abstract string VariantName { get; } -} - -public abstract class ContainerVariantBase : ContainerVariantBase where TVariantContainer : IContainer -{ - internal TVariantContainer WrapInContainer() => (TVariantContainer)Activator.CreateInstance(typeof(TVariantContainer), this); -} - -public abstract class VariantDescriptorBase : DescriptorBase where T : DescriptorBase -{ - internal string VariantName { get; private set; } - - protected void SetVariantName(string name) => VariantName = name; -} - -internal interface IContainerVariant -{ - string VariantName { get; } -} - -internal interface IQueryContainerVariant /*: IContainerVariant*/ -{ - string QueryContainerVariantName { get; } - - TestContainer WrapInQueryContainer(); + internal ContainerBase(ContainerVariantBase variant) => Variant = variant ?? throw new ArgumentNullException(nameof(variant)); } - -internal interface IContainerVariant /*: IContainerVariant*/ where TVariantContainer : IContainer -{ - TVariantContainer WrapInContainer(); -} - -public class TestVariant : IQueryContainerVariant -{ - string IQueryContainerVariant.QueryContainerVariantName => "TEST"; - - TestContainer IQueryContainerVariant.WrapInQueryContainer() => throw new NotImplementedException(); - - //internal string VariantName => this.VariantName(); - - //public TestContainer WrapInContainer(TestContainer container) => new TestContainer(this); -} - -//internal static class IContainerVariantExtensions -//{ -// public static string VariantName(this IContainerVariant @interface) => @interface.VariantName; -//} - -public partial class TestContainer : IContainer -{ - private readonly IContainerVariant _variant; - - internal TestContainer(IContainerVariant variant) => _variant = variant; -} - - -//public class QueryContainerConverter : JsonConverter -//{ -// public override QueryContainer? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) -// { -// reader.Read(); - -// if (reader.TokenType != JsonTokenType.PropertyName) -// { -// throw new JsonException(); -// } - -// var propertyName = reader.GetString(); - -// if (propertyName == "bool") -// { -// var boolQuery = JsonSerializer.Deserialize(ref reader, options); -// reader.Read(); -// return new QueryContainer(boolQuery); -// } - -// return null; -// } - -// public override void Write(Utf8JsonWriter writer, QueryContainer value, JsonSerializerOptions options) -// { -// if (value is null || value.Variant is null) -// { -// writer.WriteNullValue(); -// return; -// } - -// writer.WriteStartObject(); - -// writer.WritePropertyName(value.Variant.QueryContainerVariantName); - -// switch (value.Variant) -// { -// case BoolQuery boolQuery: -// JsonSerializer.Serialize(writer, boolQuery, options); -// break; -// case BoostingQuery boostingQuery: -// JsonSerializer.Serialize(writer, boostingQuery, options); -// break; -// } - -// writer.WriteEndObject(); -// } -//} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerVariantBase.cs b/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerVariantBase.cs new file mode 100644 index 00000000000..77e6330db9c --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Common/Containers/ContainerVariantBase.cs @@ -0,0 +1,19 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Elastic.Clients.Elasticsearch; + +public abstract class ContainerVariantBase +{ + [JsonIgnore] + internal abstract string VariantName { get; } +} + +public abstract class ContainerVariantBase : ContainerVariantBase where TVariantContainer : IContainer +{ + internal TVariantContainer WrapInContainer() => (TVariantContainer)Activator.CreateInstance(typeof(TVariantContainer), this); +} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/IndexName/IndexAlias.cs b/src/Elastic.Clients.Elasticsearch/Common/Containers/IContainer.cs similarity index 55% rename from src/Elastic.Clients.Elasticsearch/Common/Infer/IndexName/IndexAlias.cs rename to src/Elastic.Clients.Elasticsearch/Common/Containers/IContainer.cs index b9b8ecacfff..6f8dbaa5c38 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/IndexName/IndexAlias.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Containers/IContainer.cs @@ -2,13 +2,8 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -using System; -using Elastic.Transport; - namespace Elastic.Clients.Elasticsearch; -// TODO - Implement -public class IndexAlias : IUrlParameter +public interface IContainer { - public string GetString(ITransportConfiguration settings) => throw new NotImplementedException(); } diff --git a/src/Elastic.Clients.Elasticsearch/Common/Containers/IContainerVariant.cs b/src/Elastic.Clients.Elasticsearch/Common/Containers/IContainerVariant.cs new file mode 100644 index 00000000000..10a5809e6f3 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Common/Containers/IContainerVariant.cs @@ -0,0 +1,10 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +namespace Elastic.Clients.Elasticsearch; + +internal interface IContainerVariant +{ + string VariantName { get; } +} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Containers/VariantDescriptorBase.cs b/src/Elastic.Clients.Elasticsearch/Common/Containers/VariantDescriptorBase.cs new file mode 100644 index 00000000000..4f1ee704328 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Common/Containers/VariantDescriptorBase.cs @@ -0,0 +1,12 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +namespace Elastic.Clients.Elasticsearch; + +public abstract class VariantDescriptorBase : DescriptorBase where T : DescriptorBase +{ + internal string VariantName { get; private set; } + + protected void SetVariantName(string name) => VariantName = name; +} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Fields/FieldValues.cs b/src/Elastic.Clients.Elasticsearch/Common/Fields/FieldValues.cs index 046547c2b52..5a980b645fb 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Fields/FieldValues.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Fields/FieldValues.cs @@ -12,7 +12,7 @@ namespace Elastic.Clients.Elasticsearch { [JsonConverter(typeof(FieldValuesConverter))] - public class FieldValues : IsADictionaryBase + public sealed class FieldValues : IsADictionaryBase { public static readonly FieldValues Empty = new(); @@ -50,7 +50,7 @@ public TValue ValueOf(Expression> objectPath) public TValue[] Values(Field field) { if (_inferrer == null) - return new TValue[0]; + return Array.Empty(); var path = _inferrer.Field(field); return FieldArray(path); @@ -59,7 +59,7 @@ public TValue[] Values(Field field) public TValue[] ValuesOf(Expression> objectPath) { if (_inferrer == null) - return new TValue[0]; + return Array.Empty(); var field = _inferrer.Field(objectPath); return FieldArray(field); diff --git a/src/Elastic.Clients.Elasticsearch/Common/Fluent/DescriptorBase.cs b/src/Elastic.Clients.Elasticsearch/Common/Fluent/DescriptorBase.cs index 8312217971f..ebae8113f69 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Fluent/DescriptorBase.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Fluent/DescriptorBase.cs @@ -4,50 +4,16 @@ using System; using System.ComponentModel; -using System.Linq.Expressions; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text.Json; -using System.Text.Json.Serialization; -using Elastic.Clients.Elasticsearch.QueryDsl; namespace Elastic.Clients.Elasticsearch; -public interface IDescriptor { } - /// -/// Marks a type to provide it's own serialization code. -/// IMPORTANT: This should only be used for types that are only ever serialized and never deserialised, such as descriptors. +/// Internal marker for descriptors. /// -internal interface ISelfSerializable -{ - void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings); -} - -internal interface ISelfDeserializable -{ - void Deserialize(ref Utf8JsonReader reader, JsonSerializerOptions options, IElasticsearchClientSettings settings); -} - -internal interface ISelfTwoWaySerializable -{ - void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings); - void Deserialize(ref Utf8JsonReader reader, JsonSerializerOptions options, IElasticsearchClientSettings settings); -} - -internal interface IFactoryDeserializable -{ -} - -internal abstract class UnionFactory -{ - internal abstract T Deserialize(ref Utf8JsonReader reader, JsonSerializerOptions options); -} - - - - -// Maybe rename as SerializableDescriptorBase and move other items to DescriptorBase +internal interface IDescriptor { } public abstract class DescriptorBase : IDescriptor, ISelfSerializable where TDescriptor : DescriptorBase @@ -92,68 +58,3 @@ public abstract class DescriptorBase : IDescriptor, ISelfSerializab void ISelfSerializable.Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) => Serialize(writer, options, settings); } -//public abstract class QueryDescriptorBase : DescriptorBase, IQuery -// where TDescriptor : QueryDescriptorBase, IQuery -//{ -// internal string _name; - -// ///// -// //protected abstract bool Conditionless { get; } - -// //double? IQuery.Boost { get; set; } - -// //bool IQuery.Conditionless => Conditionless; - -// //bool IQuery.IsStrict { get; set; } - -// //bool IQuery.IsVerbatim { get; set; } - -// bool IQuery.IsWritable => true; /*Self.IsVerbatim || !Self.Conditionless;*/ - -// public TDescriptor Name(string name) => Assign(name, (a, v) => a._name = v); - -// ///// -// //public TDescriptor Boost(double? boost) => Assign(boost, (a, v) => a.Boost = v); - -// ///// -// //public TDescriptor Verbatim(bool verbatim = true) => Assign(verbatim, (a, v) => a.IsVerbatim = v); - -// ///// -// //public TDescriptor Strict(bool strict = true) => Assign(strict, (a, v) => a.IsStrict = v); -//} - -//internal abstract class QueryDescriptorConverterBase : JsonConverter where T : QueryDescriptorBase -//{ -//} - -//internal abstract class FieldNameQueryDescriptorConverterBase : JsonConverter where T : FieldNameQueryDescriptorBase -//{ -// public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => throw new NotImplementedException(); -// public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) -// { -// writer.WriteStartObject(); -// if (value._field is not null) -// { -// writer.WritePropertyName(value._field.ToString()); -// WriteInternal(writer, value, options); -// } -// writer.WriteEndObject(); -// } - -// internal abstract void WriteInternal(Utf8JsonWriter writer, T value, JsonSerializerOptions options); -//} - -//public abstract class FieldNameQueryDescriptorBase : QueryDescriptorBase -// where TDescriptor : FieldNameQueryDescriptorBase -//{ -// internal Field _field; - -// //bool IQuery.IsStrict { get; set; } - -// //bool IQuery.IsVerbatim { get; set; } - -// public TDescriptor Field(Field field) => Assign(field, (a, v) => a._field = v); - -// public TDescriptor Field(Expression> objectPath) => -// Assign(objectPath, (a, v) => a._field = v); -//} diff --git a/src/Elastic.Clients.Elasticsearch/Common/ForAttribute.cs b/src/Elastic.Clients.Elasticsearch/Common/ForAttribute.cs deleted file mode 100644 index 42f568e4db0..00000000000 --- a/src/Elastic.Clients.Elasticsearch/Common/ForAttribute.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Licensed to Elasticsearch B.V under one or more agreements. -// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -using System; - -namespace Elastic.Clients.Elasticsearch -{ - - ///// - ///// Makes it explicit which API this request interface maps, the name of the interface informs - ///// The generator how to name related types - ///// - //[AttributeUsage(AttributeTargets.Interface)] - //internal class MapsApiAttribute : Attribute - //{ - // // ReSharper disable once UnusedParameter.Local - // public MapsApiAttribute(string restSpecName) { } - //} - - ///// - ///// The preferred way to wire in a custom response formatter is for requests to override - ///// however sometimes a request does not have - ///// access to enough type information. This attribute will set up the see - ///// in the generated client methods instead. - ///// - //[AttributeUsage(AttributeTargets.Interface)] - //internal class ResponseBuilderWithGeneric : Attribute - //{ - // // ReSharper disable once UnusedParameter.Local - // public ResponseBuilderWithGeneric(string pathToBuilder) { } - //} - - public interface IDocumentPath - { - Id Id { get; set; } - IndexName Index { get; set; } - } - - public class DocumentPath : IEquatable>, IDocumentPath - { - public DocumentPath(T document) : this(Elasticsearch.Id.From(document)) => Document = document; - - public DocumentPath(Id id) - { - Self.Id = id; - Self.Index = typeof(T); - } - - internal T Document { get; set; } - internal IDocumentPath Self => this; - Id IDocumentPath.Id { get; set; } - IndexName IDocumentPath.Index { get; set; } - - public bool Equals(DocumentPath other) - { - IDocumentPath o = other, s = Self; - return s.Index.NullOrEquals(o.Index) && s.Id.NullOrEquals(o.Id) && (Document?.Equals(other.Document) ?? true); - } - - public static DocumentPath Id(Id id) => new DocumentPath(id); - - public static DocumentPath Id(T @object) => new DocumentPath(@object); - - public static implicit operator DocumentPath(T @object) => @object == null ? null : new DocumentPath(@object); - - public static implicit operator DocumentPath(Id id) => id == null ? null : new DocumentPath(id); - - public static implicit operator DocumentPath(long id) => new DocumentPath(id); - - public static implicit operator DocumentPath(string id) => id.IsNullOrEmpty() ? null : new DocumentPath(id); - - public static implicit operator DocumentPath(Guid id) => new DocumentPath(id); - - public DocumentPath Index(IndexName index) - { - if (index == null) - return this; - - Self.Index = index; - return this; - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = Self.Index?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (Self.Id?.GetHashCode() ?? 0); - return hashCode; - } - } - - public override bool Equals(object obj) - { - switch (obj) - { - case DocumentPath d: - return Equals(d); - default: - return false; - } - } - - public static bool operator ==(DocumentPath x, DocumentPath y) => Equals(x, y); - - public static bool operator !=(DocumentPath x, DocumentPath y) => !Equals(x, y); - } -} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/DocumentPath/DocumentPath.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/DocumentPath/DocumentPath.cs index eae1892262b..c7ffa397e42 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/DocumentPath/DocumentPath.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/DocumentPath/DocumentPath.cs @@ -2,84 +2,77 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -namespace Elastic.Clients.Elasticsearch +using System; + +namespace Elastic.Clients.Elasticsearch; + +public interface IDocumentPath +{ + Id Id { get; set; } + IndexName Index { get; set; } +} + +public sealed class DocumentPath : IEquatable>, IDocumentPath { - //public interface IDocumentPath - //{ - // Id Id { get; set; } - // IndexName Index { get; set; } - //} - - //public class DocumentPath : IEquatable>, IDocumentPath where T : class - //{ - // public DocumentPath(T document) : this(Elastic.Clients.Elasticsearch.Id.From(document)) => Document = document; - - // public DocumentPath(Id id) - // { - // Self.Id = id; - // Self.Index = typeof(T); - // } - - // internal T Document { get; set; } - // internal IDocumentPath Self => this; - // Id IDocumentPath.Id { get; set; } - // IndexName IDocumentPath.Index { get; set; } - - // public bool Equals(DocumentPath other) - // { - // IDocumentPath o = other, s = Self; - // return s.Index.NullOrEquals(o.Index) && s.Id.NullOrEquals(o.Id) && - // (Document?.Equals(other.Document) ?? true); - // } - - // public static DocumentPath Id(Id id) => new(id); - - // public static DocumentPath Id(T @object) => new(@object); - - // public static implicit operator DocumentPath(T @object) => - // @object == null ? null : new DocumentPath(@object); - - // public static implicit operator DocumentPath(Id id) => id == null ? null : new DocumentPath(id); - - // public static implicit operator DocumentPath(long id) => new(id); - - // public static implicit operator DocumentPath(string id) => - // id.IsNullOrEmpty() ? null : new DocumentPath(id); - - // public static implicit operator DocumentPath(Guid id) => new(id); - - // public DocumentPath Index(IndexName index) - // { - // if (index == null) - // return this; - - // Self.Index = index; - // return this; - // } - - // public override int GetHashCode() - // { - // unchecked - // { - // var hashCode = Self.Index?.GetHashCode() ?? 0; - // hashCode = (hashCode * 397) ^ (Self.Id?.GetHashCode() ?? 0); - // return hashCode; - // } - // } - - // public override bool Equals(object obj) - // { - // switch (obj) - // { - // case DocumentPath d: - // return Equals(d); - // default: - // return false; - // } - // } - - // public static bool operator ==(DocumentPath x, DocumentPath y) => Equals(x, y); - - // public static bool operator !=(DocumentPath x, DocumentPath y) => !Equals(x, y); - //} + public DocumentPath(T document) : this(Elasticsearch.Id.From(document)) => Document = document; + + public DocumentPath(Id id) + { + Self.Id = id; + Self.Index = typeof(T); + } + + internal T Document { get; set; } + internal IDocumentPath Self => this; + Id IDocumentPath.Id { get; set; } + IndexName IDocumentPath.Index { get; set; } + + public bool Equals(DocumentPath other) + { + IDocumentPath o = other, s = Self; + return s.Index.NullOrEquals(o.Index) && s.Id.NullOrEquals(o.Id) && (Document?.Equals(other.Document) ?? true); + } + + public static DocumentPath Id(Id id) => new(id); + + public static DocumentPath Id(T @object) => new(@object); + + public static implicit operator DocumentPath(T @object) => @object == null ? null : new DocumentPath(@object); + + public static implicit operator DocumentPath(Id id) => id == null ? null : new DocumentPath(id); + + public static implicit operator DocumentPath(long id) => new(id); + + public static implicit operator DocumentPath(string id) => id.IsNullOrEmpty() ? null : new DocumentPath(id); + + public static implicit operator DocumentPath(Guid id) => new(id); + + public DocumentPath Index(IndexName index) + { + if (index == null) + return this; + + Self.Index = index; + return this; + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = Self.Index?.GetHashCode() ?? 0; + hashCode = (hashCode * 397) ^ (Self.Id?.GetHashCode() ?? 0); + return hashCode; + } + } + + public override bool Equals(object obj) => obj switch + { + DocumentPath d => Equals(d), + _ => false, + }; + + public static bool operator ==(DocumentPath x, DocumentPath y) => Equals(x, y); + + public static bool operator !=(DocumentPath x, DocumentPath y) => !Equals(x, y); } diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/Field/Field.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/Field/Field.cs index 6a469d1d327..0896bb3e847 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/Field/Field.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/Field/Field.cs @@ -10,190 +10,169 @@ using System.Text.Json.Serialization; using Elastic.Transport; -namespace Elastic.Clients.Elasticsearch -{ - // TODO - This is a prototype - public struct FieldSettings - { - public double? Boost { get; set; } - public string? Format { get; set; } - } - - // TODO - Make struct - [JsonConverter(typeof(FieldConverter))] - [DebuggerDisplay("{" + nameof(DebugDisplay) + ",nq}")] - public class Field : IEquatable, IUrlParameter - { - private readonly object _comparisonValue; - private readonly Type _type; +namespace Elastic.Clients.Elasticsearch; - // TODO - Future idea - public Field(string name, FieldSettings settings) - { - name.ThrowIfNullOrEmpty(nameof(name)); - - // todo -throw is no settings - Name = ParseFieldName(name, out var b); - Boost = b ?? settings.Boost; - Format = settings.Format; - _comparisonValue = Name; - } +[JsonConverter(typeof(FieldConverter))] +[DebuggerDisplay("{" + nameof(DebugDisplay) + ",nq}")] +public sealed class Field : IEquatable, IUrlParameter +{ + private readonly object _comparisonValue; + private readonly Type _type; - public Field(string name) : this(name, null, null) { } + public Field(string name) : this(name, null, null) { } - public Field(string name, double boost) : this(name, boost, null) { } + public Field(string name, double boost) : this(name, boost, null) { } - public Field(string name, string format) : this(name, null, format) { } + public Field(string name, string format) : this(name, null, format) { } - public Field(string name, double? boost, string? format) - { - name.ThrowIfNullOrEmpty(nameof(name)); - Name = ParseFieldName(name, out var b); - Boost = b ?? boost; - Format = format; - _comparisonValue = Name; - } + public Field(string name, double? boost, string? format) + { + name.ThrowIfNullOrEmpty(nameof(name)); + Name = ParseFieldName(name, out var b); + Boost = b ?? boost; + Format = format; + _comparisonValue = Name; + } - public Field(Expression expression, double? boost = null, string format = null) - { - Expression = expression ?? throw new ArgumentNullException(nameof(expression)); - Boost = boost; - Format = format; - _comparisonValue = expression.ComparisonValueFromExpression(out var type, out var cachable); - _type = type; - CachableExpression = cachable; - } + public Field(Expression expression, double? boost = null, string format = null) + { + Expression = expression ?? throw new ArgumentNullException(nameof(expression)); + Boost = boost; + Format = format; + _comparisonValue = expression.ComparisonValueFromExpression(out var type, out var cachable); + _type = type; + CachableExpression = cachable; + } - public Field(PropertyInfo property, double? boost = null, string format = null) - { - Property = property ?? throw new ArgumentNullException(nameof(property)); - Boost = boost; - Format = format; - _comparisonValue = property; - _type = property.DeclaringType; - } + public Field(PropertyInfo property, double? boost = null, string format = null) + { + Property = property ?? throw new ArgumentNullException(nameof(property)); + Boost = boost; + Format = format; + _comparisonValue = property; + _type = property.DeclaringType; + } - /// - /// A boost to apply to the field - /// - public double? Boost { get; set; } - - /// - /// A format to apply to the field. - /// - /// - /// Can be used only for Doc Value Fields Elasticsearch 6.4.0+ - /// - public string? Format { get; set; } - - [JsonIgnore] - public bool CachableExpression { get; } - - /// - /// An expression from which the name of the field can be inferred - /// - public Expression Expression { get; } - - /// - /// The name of the field - /// - public string Name { get; } - - /// - /// A property from which the name of the field can be inferred - /// - public PropertyInfo Property { get; } - - internal string DebugDisplay => - $"{Expression?.ToString() ?? PropertyDebug ?? Name}{(Boost.HasValue ? "^" + Boost.Value : string.Empty)}" - + $"{(!string.IsNullOrEmpty(Format) ? " format: " + Format : string.Empty)}" - + $"{(_type == null ? string.Empty : " typeof: " + _type.Name)}"; - - private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}"; - - public bool Equals(Field other) => _type != null - ? other != null && _type == other._type && _comparisonValue.Equals(other._comparisonValue) - : other != null && _comparisonValue.Equals(other._comparisonValue); - - string IUrlParameter.GetString(ITransportConfiguration? settings) + /// + /// A boost to apply to the field + /// + public double? Boost { get; set; } + + /// + /// A format to apply to the field. + /// + /// + /// Can be used only for Doc Value Fields Elasticsearch 6.4.0+ + /// + public string? Format { get; set; } + + [JsonIgnore] + public bool CachableExpression { get; } + + /// + /// An expression from which the name of the field can be inferred + /// + public Expression Expression { get; } + + /// + /// The name of the field + /// + public string Name { get; } + + /// + /// A property from which the name of the field can be inferred + /// + public PropertyInfo Property { get; } + + internal string DebugDisplay => + $"{Expression?.ToString() ?? PropertyDebug ?? Name}{(Boost.HasValue ? "^" + Boost.Value : string.Empty)}" + + $"{(!string.IsNullOrEmpty(Format) ? " format: " + Format : string.Empty)}" + + $"{(_type == null ? string.Empty : " typeof: " + _type.Name)}"; + + private string PropertyDebug => Property == null ? null : $"PropertyInfo: {Property.Name}"; + + public bool Equals(Field other) => _type != null + ? other != null && _type == other._type && _comparisonValue.Equals(other._comparisonValue) + : other != null && _comparisonValue.Equals(other._comparisonValue); + + string IUrlParameter.GetString(ITransportConfiguration? settings) + { + if (!(settings is IElasticsearchClientSettings ElasticsearchSettings)) { - if (!(settings is IElasticsearchClientSettings ElasticsearchSettings)) - { - throw new ArgumentNullException(nameof(settings), - $"Can not resolve {nameof(Field)} if no {nameof(IElasticsearchClientSettings)} is provided"); - } - - return ElasticsearchSettings.Inferrer.Field(this); + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(Field)} if no {nameof(IElasticsearchClientSettings)} is provided"); } - public override string ToString() => DebugDisplay; + return ElasticsearchSettings.Inferrer.Field(this); + } - public Fields And(Field field) => new(new[] { this, field }); + public override string ToString() => DebugDisplay; - public Fields And(Expression> field, double? boost = null, string format = null) - where T : class => - new(new[] { this, new Field(field, boost, format) }); + public Fields And(Field field) => new(new[] { this, field }); - public Fields And(Expression> field, double? boost = null, string format = null) - where T : class => - new(new[] { this, new Field(field, boost, format) }); + public Fields And(Expression> field, double? boost = null, string format = null) + where T : class => + new(new[] { this, new Field(field, boost, format) }); - public Fields And(string field, double? boost = null, string format = null) => - new(new[] { this, new Field(field, boost, format) }); + public Fields And(Expression> field, double? boost = null, string format = null) + where T : class => + new(new[] { this, new Field(field, boost, format) }); - public Fields And(PropertyInfo property, double? boost = null, string format = null) => - new(new[] { this, new Field(property, boost, format) }); + public Fields And(string field, double? boost = null, string format = null) => + new(new[] { this, new Field(field, boost, format) }); - private static string ParseFieldName(string name, out double? boost) - { - boost = null; - if (name == null) - return null; + public Fields And(PropertyInfo property, double? boost = null, string format = null) => + new(new[] { this, new Field(property, boost, format) }); - var caretIndex = name.IndexOf('^'); - if (caretIndex == -1) - return name; + private static string ParseFieldName(string name, out double? boost) + { + boost = null; + if (name == null) + return null; - var parts = name.Split(new[] { '^' }, 2, StringSplitOptions.RemoveEmptyEntries); - name = parts[0]; - boost = double.Parse(parts[1], CultureInfo.InvariantCulture); + var caretIndex = name.IndexOf('^'); + if (caretIndex == -1) return name; - } - public static implicit operator Field(string name) => name.IsNullOrEmpty() ? null : new Field(name); + var parts = name.Split(new[] { '^' }, 2, StringSplitOptions.RemoveEmptyEntries); + name = parts[0]; + boost = double.Parse(parts[1], CultureInfo.InvariantCulture); + return name; + } + + public static implicit operator Field(string name) => name.IsNullOrEmpty() ? null : new Field(name); - public static implicit operator Field(Expression expression) => - expression == null ? null : new Field(expression); + public static implicit operator Field(Expression expression) => + expression == null ? null : new Field(expression); - public static implicit operator Field(PropertyInfo property) => property == null ? null : new Field(property); + public static implicit operator Field(PropertyInfo property) => property == null ? null : new Field(property); - public override int GetHashCode() + public override int GetHashCode() + { + unchecked { - unchecked - { - var hashCode = _comparisonValue?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ (_type?.GetHashCode() ?? 0); - return hashCode; - } + var hashCode = _comparisonValue?.GetHashCode() ?? 0; + hashCode = (hashCode * 397) ^ (_type?.GetHashCode() ?? 0); + return hashCode; } + } - public override bool Equals(object obj) + public override bool Equals(object obj) + { + switch (obj) { - switch (obj) - { - case string s: - return Equals(s); - case PropertyInfo p: - return Equals(p); - case Field f: - return Equals(f); - default: - return false; - } + case string s: + return Equals(s); + case PropertyInfo p: + return Equals(p); + case Field f: + return Equals(f); + default: + return false; } + } - public static bool operator ==(Field x, Field y) => Equals(x, y); + public static bool operator ==(Field x, Field y) => Equals(x, y); - public static bool operator !=(Field x, Field y) => !Equals(x, y); - } + public static bool operator !=(Field x, Field y) => !Equals(x, y); } diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/Field/FieldExpressionVisitor.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/Field/FieldExpressionVisitor.cs index 25176bd0b59..588507a7814 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/Field/FieldExpressionVisitor.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/Field/FieldExpressionVisitor.cs @@ -2,10 +2,6 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -//// Licensed to Elasticsearch B.V under one or more agreements. -//// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -//// See the LICENSE file in the project root for more information. - //using System.Collections; //using System.Collections.Generic; //using System.Collections.ObjectModel; diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/Fields/Fields.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/Fields/Fields.cs index 02ed6aeb4e0..728f37f0186 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/Fields/Fields.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/Fields/Fields.cs @@ -107,7 +107,7 @@ public override void Write(Utf8JsonWriter writer, Field value, JsonSerializerOpt [JsonConverter(typeof(FieldsConverter))] [DebuggerDisplay("{DebugDisplay,nq}")] -public partial class Fields : IUrlParameter, IEnumerable, IEquatable +public sealed class Fields : IUrlParameter, IEnumerable, IEquatable { internal readonly List ListOfFields; diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/IndexUuid/IndexUuid.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/IndexUuid/IndexUuid.cs deleted file mode 100644 index da38418e272..00000000000 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/IndexUuid/IndexUuid.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to Elasticsearch B.V under one or more agreements. -// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -using System; -using Elastic.Transport; - -namespace Elastic.Clients.Elasticsearch.Core -{ - public class IndexUuid : IUrlParameter, IEquatable - { - public IndexUuid(string value) => Value = value ?? throw new ArgumentNullException(nameof(value)); - public string Value { get; } - - public bool Equals(IndexUuid other) - { - if (ReferenceEquals(null, other)) - return false; - if (ReferenceEquals(this, other)) - return true; - - return Value == other.Value; - } - - public string GetString(ITransportConfiguration settings) => Value; - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) - return false; - if (ReferenceEquals(this, obj)) - return true; - if (obj.GetType() != GetType()) - return false; - - return Equals((IndexUuid)obj); - } - - public override int GetHashCode() => Value != null ? Value.GetHashCode() : 0; - - public static bool operator ==(IndexUuid left, IndexUuid right) => Equals(left, right); - - public static bool operator !=(IndexUuid left, IndexUuid right) => !Equals(left, right); - - public static implicit operator IndexUuid(string value) => - string.IsNullOrEmpty(value) ? null : new IndexUuid(value); - } -} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/Indices/Indices.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/Indices/Indices.cs index 4ea6a37be37..e41855c8d81 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/Indices/Indices.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/Indices/Indices.cs @@ -14,7 +14,7 @@ namespace Elastic.Clients.Elasticsearch; [DebuggerDisplay("{DebugDisplay,nq}")] [JsonConverter(typeof(IndicesJsonConverter))] -public class Indices : Union, IUrlParameter +public sealed class Indices : Union, IUrlParameter { internal Indices(AllIndicesMarker all) : base(all) { } diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/Inferrer.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/Inferrer.cs index 0f361a1c2e2..2dd03a82371 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/Inferrer.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/Inferrer.cs @@ -20,7 +20,7 @@ namespace Elastic.Clients.Elasticsearch { - public class Inferrer + public sealed class Inferrer { private readonly IElasticsearchClientSettings _elasticsearchClientSettings; @@ -79,46 +79,7 @@ public Inferrer(IElasticsearchClientSettings elasticsearchClientSettings) public string Routing(Type type, object instance) => RoutingResolver.Resolve(type, instance); } - public class RelationNameResolver - { - private readonly IElasticsearchClientSettings _transportClientSettings; - private readonly ConcurrentDictionary _relationNames = new(); - - public RelationNameResolver(IElasticsearchClientSettings connectionSettings) - { - connectionSettings.ThrowIfNull(nameof(connectionSettings)); - _transportClientSettings = connectionSettings; - } - - public string Resolve() => Resolve(typeof(T)); - - public string Resolve(RelationName t) => t?.Name ?? ResolveType(t?.Type); - - private string ResolveType(Type type) - { - if (type == null) - return null; - - if (_relationNames.TryGetValue(type, out var typeName)) - return typeName; - - if (_transportClientSettings.DefaultRelationNames.TryGetValue(type, out typeName)) - { - _relationNames.TryAdd(type, typeName); - return typeName; - } - - //var att = ElasticsearchTypeAttribute.From(type); - //if (att != null && !att.RelationName.IsNullOrEmpty()) - // typeName = att.RelationName; - //else - - typeName = type.Name.ToLowerInvariant(); - - _relationNames.TryAdd(type, typeName); - return typeName; - } - } + public class RoutingResolver { @@ -337,106 +298,9 @@ public override void Write(Utf8JsonWriter writer, JoinField value, JsonSerialize } } - [JsonConverter(typeof(RelationNameConverter))] - public class RelationName : IEquatable, IUrlParameter - { - private RelationName(string type) => Name = type; - - private RelationName(Type type) => Type = type; - - public string Name { get; } - public Type Type { get; } - - internal string DebugDisplay => Type == null ? Name : $"{nameof(RelationName)} for typeof: {Type?.Name}"; - - private static int TypeHashCode { get; } = typeof(RelationName).GetHashCode(); - - public bool Equals(RelationName other) => EqualsMarker(other); - - string IUrlParameter.GetString(ITransportConfiguration? settings) - { - if (settings is not IElasticsearchClientSettings nestSettings) - throw new ArgumentNullException(nameof(settings), - $"Can not resolve {nameof(RelationName)} if no {nameof(IElasticsearchClientSettings)} is provided"); - - return nestSettings.Inferrer.RelationName(this); - } - - public static RelationName From() => typeof(T); - - public static RelationName Create(Type type) => GetRelationNameForType(type); - - public static RelationName Create() where T : class => GetRelationNameForType(typeof(T)); - - private static RelationName GetRelationNameForType(Type type) => new(type); - - public static implicit operator RelationName(string typeName) => typeName.IsNullOrEmpty() ? null : new RelationName(typeName); - - public static implicit operator RelationName(Type type) => type == null ? null : new RelationName(type); - - public override int GetHashCode() - { - unchecked - { - var result = TypeHashCode; - result = (result * 397) ^ (Name?.GetHashCode() ?? Type?.GetHashCode() ?? 0); - return result; - } - } - - public static bool operator ==(RelationName left, RelationName right) => Equals(left, right); - - public static bool operator !=(RelationName left, RelationName right) => !Equals(left, right); - - public override bool Equals(object obj) => - obj is string s ? EqualsString(s) : obj is RelationName r && EqualsMarker(r); - - public bool EqualsMarker(RelationName other) - { - if (!Name.IsNullOrEmpty() && other != null && !other.Name.IsNullOrEmpty()) - return EqualsString(other.Name); - if (Type != null && other?.Type != null) - return Type == other.Type; - - return false; - } - - private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == Name; - - public override string ToString() => DebugDisplay; - - } - - internal sealed class RelationNameConverter : JsonConverter - { - private readonly IElasticsearchClientSettings _settings; - - public RelationNameConverter(IElasticsearchClientSettings settings) => _settings = settings; - - public override RelationName? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - if (reader.TokenType == JsonTokenType.String) - { - RelationName relationName = reader.GetString(); - return relationName; - } - - return null; - } - - public override void Write(Utf8JsonWriter writer, RelationName value, JsonSerializerOptions options) - { - if (value is null) - { - writer.WriteNullValue(); - return; - } - - var relationName = _settings.Inferrer.RelationName(value); - writer.WriteStringValue(relationName); - } - } + + internal class FieldResolver { protected readonly ConcurrentDictionary Fields = new(); diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/Name/Name.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/Name/Name.cs deleted file mode 100644 index 22bfed44027..00000000000 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/Name/Name.cs +++ /dev/null @@ -1,91 +0,0 @@ -// Licensed to Elasticsearch B.V under one or more agreements. -// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -using System; -using System.Diagnostics; -using System.Text.Json.Serialization; -using Elastic.Transport; - -namespace Elastic.Clients.Elasticsearch -{ - [DebuggerDisplay("{DebugDisplay,nq}")] - [JsonConverter(typeof(StringAliasConverter))] - public class Name : IEquatable, IUrlParameter - { - public Name(string name) => Value = name?.Trim(); - - internal string Value { get; } - - private string DebugDisplay => Value; - - private static int TypeHashCode { get; } = typeof(Name).GetHashCode(); - - public bool Equals(Name other) => EqualsString(other?.Value); - - string IUrlParameter.GetString(ITransportConfiguration? settings) => Value; - - public override string ToString() => DebugDisplay; - - public static implicit operator Name(string name) => name.IsNullOrEmpty() ? null : new Name(name); - - public static bool operator ==(Name left, Name right) => Equals(left, right); - - public static bool operator !=(Name left, Name right) => !Equals(left, right); - - public override bool Equals(object obj) => - obj is string s ? EqualsString(s) : obj is Name i && EqualsString(i.Value); - - private bool EqualsString(string other) => !other.IsNullOrEmpty() && other.Trim() == Value; - - public override int GetHashCode() - { - unchecked - { - var result = TypeHashCode; - result = (result * 397) ^ (Value?.GetHashCode() ?? 0); - return result; - } - } - } - - [DebuggerDisplay("{DebugDisplay,nq}")] - [JsonConverter(typeof(StringAliasConverter))] - public class Username : IEquatable, IUrlParameter - { - public Username(string name) => Value = name?.Trim(); - - internal string Value { get; } - - private string DebugDisplay => Value; - - private static int TypeHashCode { get; } = typeof(Username).GetHashCode(); - - public bool Equals(Username other) => EqualsString(other?.Value); - - string IUrlParameter.GetString(ITransportConfiguration? settings) => Value; - - public override string ToString() => DebugDisplay; - - public static implicit operator Username(string name) => name.IsNullOrEmpty() ? null : new Username(name); - - public static bool operator ==(Username left, Username right) => Equals(left, right); - - public static bool operator !=(Username left, Username right) => !Equals(left, right); - - public override bool Equals(object obj) => - obj is string s ? EqualsString(s) : obj is Username i && EqualsString(i.Value); - - private bool EqualsString(string other) => !other.IsNullOrEmpty() && other.Trim() == Value; - - public override int GetHashCode() - { - unchecked - { - var result = TypeHashCode; - result = (result * 397) ^ (Value?.GetHashCode() ?? 0); - return result; - } - } - } -} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/PropertyName/PropertyName.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/PropertyName/PropertyName.cs index 210486b7ea3..a1436da4afc 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/PropertyName/PropertyName.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/PropertyName/PropertyName.cs @@ -11,14 +11,9 @@ namespace Elastic.Clients.Elasticsearch { - public interface IDictionaryKey - { - string Key { get; } - } - [DebuggerDisplay("{" + nameof(DebugDisplay) + ",nq}")] [JsonConverter(typeof(PropertyNameConverter))] - public class PropertyName : IEquatable, IUrlParameter, IDictionaryKey + public sealed class PropertyName : IEquatable, IUrlParameter, IDictionaryKey { private readonly object _comparisonValue; private readonly Type _type; @@ -67,8 +62,7 @@ string IUrlParameter.GetString(ITransportConfiguration? settings) $"Can not resolve {nameof(PropertyName)} if no {nameof(IElasticsearchClientSettings)} is provided"); } - return string.Empty; - //return elasticsearchSettings.Inferrer.PropertyName(this); + return elasticsearchSettings.Inferrer.PropertyName(this); } public override string ToString() => DebugDisplay; diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/RelationName/RelationName.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/RelationName/RelationName.cs index cf305c4d4e7..8a9cdb31dd6 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/RelationName/RelationName.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/RelationName/RelationName.cs @@ -2,79 +2,108 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -namespace Elastic.Clients.Elasticsearch +using System; +using Elastic.Transport; +using System.Text.Json.Serialization; +using System.Text.Json; + +namespace Elastic.Clients.Elasticsearch; + +[JsonConverter(typeof(RelationNameConverter))] +public sealed class RelationName : IEquatable, IUrlParameter { - //[DebuggerDisplay("{" + nameof(DebugDisplay) + ",nq}")] - //public class RelationName : IEquatable, IUrlParameter - //{ - // private RelationName(string type) => Name = type; + private RelationName(string type) => Name = type; - // private RelationName(Type type) => Type = type; + private RelationName(Type type) => Type = type; - // public string Name { get; } - // public Type Type { get; } + public string Name { get; } + public Type Type { get; } - // internal string DebugDisplay => Type == null ? Name : $"{nameof(RelationName)} for typeof: {Type?.Name}"; + internal string DebugDisplay => Type == null ? Name : $"{nameof(RelationName)} for typeof: {Type?.Name}"; - // private static int TypeHashCode { get; } = typeof(RelationName).GetHashCode(); + private static int TypeHashCode { get; } = typeof(RelationName).GetHashCode(); - // public bool Equals(RelationName other) => EqualsMarker(other); + public bool Equals(RelationName other) => EqualsMarker(other); - // string IUrlParameter.GetString(ITransportConfiguration? settings) - // { - // if (!(settings is IElasticsearchClientSettings Elastic.Clients.ElasticsearchSettings)) - // { - // throw new ArgumentNullException(nameof(settings), - // $"Can not resolve {nameof(RelationName)} if no {nameof(IElasticsearchClientSettings)} is provided"); - // } + string IUrlParameter.GetString(ITransportConfiguration? settings) + { + if (settings is not IElasticsearchClientSettings nestSettings) + throw new ArgumentNullException(nameof(settings), + $"Can not resolve {nameof(RelationName)} if no {nameof(IElasticsearchClientSettings)} is provided"); - // //return Elastic.Clients.ElasticsearchSettings.Inferrer.RelationName(this); + return nestSettings.Inferrer.RelationName(this); + } - // return string.Empty; - // } + public static RelationName From() => typeof(T); - // public static RelationName From() => typeof(T); + public static RelationName Create(Type type) => GetRelationNameForType(type); - // public static RelationName Create(Type type) => GetRelationNameForType(type); + public static RelationName Create() where T : class => GetRelationNameForType(typeof(T)); - // public static RelationName Create() where T : class => GetRelationNameForType(typeof(T)); + private static RelationName GetRelationNameForType(Type type) => new(type); - // private static RelationName GetRelationNameForType(Type type) => new(type); + public static implicit operator RelationName(string typeName) => typeName.IsNullOrEmpty() ? null : new RelationName(typeName); - // public static implicit operator RelationName(string typeName) => - // typeName.IsNullOrEmpty() ? null : new RelationName(typeName); + public static implicit operator RelationName(Type type) => type == null ? null : new RelationName(type); - // public static implicit operator RelationName(Type type) => type == null ? null : new RelationName(type); + public override int GetHashCode() + { + unchecked + { + var result = TypeHashCode; + result = (result * 397) ^ (Name?.GetHashCode() ?? Type?.GetHashCode() ?? 0); + return result; + } + } - // public override int GetHashCode() - // { - // unchecked - // { - // var result = TypeHashCode; - // result = (result * 397) ^ (Name?.GetHashCode() ?? Type?.GetHashCode() ?? 0); - // return result; - // } - // } + public static bool operator ==(RelationName left, RelationName right) => Equals(left, right); - // public static bool operator ==(RelationName left, RelationName right) => Equals(left, right); + public static bool operator !=(RelationName left, RelationName right) => !Equals(left, right); - // public static bool operator !=(RelationName left, RelationName right) => !Equals(left, right); + public override bool Equals(object obj) => + obj is string s ? EqualsString(s) : obj is RelationName r && EqualsMarker(r); - // public override bool Equals(object obj) => - // obj is string s ? EqualsString(s) : obj is RelationName r && EqualsMarker(r); + public bool EqualsMarker(RelationName other) + { + if (!Name.IsNullOrEmpty() && other != null && !other.Name.IsNullOrEmpty()) + return EqualsString(other.Name); + if (Type != null && other?.Type != null) + return Type == other.Type; - // public bool EqualsMarker(RelationName other) - // { - // if (!Name.IsNullOrEmpty() && other != null && !other.Name.IsNullOrEmpty()) - // return EqualsString(other.Name); - // if (Type != null && other?.Type != null) - // return Type == other.Type; + return false; + } - // return false; - // } + private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == Name; - // private bool EqualsString(string other) => !other.IsNullOrEmpty() && other == Name; + public override string ToString() => DebugDisplay; +} - // public override string ToString() => DebugDisplay; - //} +internal sealed class RelationNameConverter : JsonConverter +{ + private readonly IElasticsearchClientSettings _settings; + + public RelationNameConverter(IElasticsearchClientSettings settings) => _settings = settings; + + public override RelationName? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.String) + { + RelationName relationName = reader.GetString(); + return relationName; + } + + return null; + } + + public override void Write(Utf8JsonWriter writer, RelationName value, JsonSerializerOptions options) + { + if (value is null) + { + writer.WriteNullValue(); + return; + } + + var relationName = _settings.Inferrer.RelationName(value); + writer.WriteStringValue(relationName); + } } diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/RelationName/RelationNameResolver.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/RelationName/RelationNameResolver.cs index 6a1548aa63d..d14ed4c4344 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/RelationName/RelationNameResolver.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/RelationName/RelationNameResolver.cs @@ -2,49 +2,43 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. -//using System; -//using System.Collections.Concurrent; - -//namespace Elastic.Clients.Elasticsearch -//{ -// public class RelationNameResolver -// { -// private readonly ITransportClientSettingsValues _transportClientSettings; -// private readonly ConcurrentDictionary _relationNames = new ConcurrentDictionary(); - -// public RelationNameResolver(ITransportClientSettingsValues connectionSettings) -// { -// connectionSettings.ThrowIfNull(nameof(connectionSettings)); -// _transportClientSettings = connectionSettings; -// } - -// public string Resolve() where T : class => Resolve(typeof(T)); - -// public string Resolve(RelationName t) => t?.Name ?? ResolveType(t?.Type); - -// private string ResolveType(Type type) -// { -// if (type == null) return null; - -// string typeName; - -// if (_relationNames.TryGetValue(type, out typeName)) -// return typeName; - -// if (_transportClientSettings.DefaultRelationNames.TryGetValue(type, out typeName)) -// { -// _relationNames.TryAdd(type, typeName); -// return typeName; -// } - -// var att = ElasticsearchTypeAttribute.From(type); -// if (att != null && !att.RelationName.IsNullOrEmpty()) -// typeName = att.RelationName; -// else -// typeName = type.Name.ToLowerInvariant(); - -// _relationNames.TryAdd(type, typeName); -// return typeName; -// } -// } -//} +using System; +using System.Collections.Concurrent; + +namespace Elastic.Clients.Elasticsearch; + +internal sealed class RelationNameResolver +{ + private readonly IElasticsearchClientSettings _transportClientSettings; + private readonly ConcurrentDictionary _relationNames = new(); + + public RelationNameResolver(IElasticsearchClientSettings connectionSettings) + { + connectionSettings.ThrowIfNull(nameof(connectionSettings)); + _transportClientSettings = connectionSettings; + } + + public string Resolve() => Resolve(typeof(T)); + + public string Resolve(RelationName t) => t?.Name ?? ResolveType(t?.Type); + + private string ResolveType(Type type) + { + if (type == null) + return null; + + if (_relationNames.TryGetValue(type, out var typeName)) + return typeName; + + if (_transportClientSettings.DefaultRelationNames.TryGetValue(type, out typeName)) + { + _relationNames.TryAdd(type, typeName); + return typeName; + } + + typeName = type.Name.ToLowerInvariant(); + + _relationNames.TryAdd(type, typeName); + return typeName; + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Infer/Timestamp/Timestamp.cs b/src/Elastic.Clients.Elasticsearch/Common/Infer/Timestamp/Timestamp.cs index 3c81cc088fe..f00931cd739 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Infer/Timestamp/Timestamp.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Infer/Timestamp/Timestamp.cs @@ -8,7 +8,7 @@ namespace Elastic.Clients.Elasticsearch { - public class Timestamp : IUrlParameter, IEquatable + public sealed class Timestamp : IUrlParameter, IEquatable { internal readonly long Value; @@ -25,20 +25,13 @@ public class Timestamp : IUrlParameter, IEquatable public static implicit operator long(Timestamp categoryId) => categoryId.Value; - public override bool Equals(object obj) + public override bool Equals(object obj) => obj switch { - switch (obj) - { - case int l: - return Value == l; - case long l: - return Value == l; - case Timestamp i: - return Value == i.Value; - default: - return false; - } - } + int l => Value == l, + long l => Value == l, + Timestamp i => Value == i.Value, + _ => false, + }; public override int GetHashCode() => Value.GetHashCode(); diff --git a/src/Elastic.Clients.Elasticsearch/Common/IsADictionaryBase.cs b/src/Elastic.Clients.Elasticsearch/Common/IsADictionaryBase.cs index fbe21b2daf4..22c8bbb3d59 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/IsADictionaryBase.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/IsADictionaryBase.cs @@ -93,7 +93,7 @@ public abstract class IsADictionaryDescriptorBase where TPromised : class, IIsADictionary { - protected IsADictionaryDescriptorBase(TPromised instance) : base(instance) { } + internal IsADictionaryDescriptorBase(TPromised instance) : base(instance) { } protected TDescriptor Assign(TKey key, TValue value) { @@ -108,7 +108,7 @@ public interface IIsAReadOnlyDictionary : IReadOnlyDictionary : IIsAReadOnlyDictionary { - protected IsAReadOnlyDictionaryBase(IReadOnlyDictionary backingDictionary) + internal IsAReadOnlyDictionaryBase(IReadOnlyDictionary backingDictionary) { if (backingDictionary == null) return; diff --git a/src/Elastic.Clients.Elasticsearch/Common/MinimumShouldMatch.cs b/src/Elastic.Clients.Elasticsearch/Common/MinimumShouldMatch.cs index 5f470f48784..ddff47e538d 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/MinimumShouldMatch.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/MinimumShouldMatch.cs @@ -4,7 +4,7 @@ namespace Elastic.Clients.Elasticsearch { - public class MinimumShouldMatch : Union + public sealed class MinimumShouldMatch : Union { public MinimumShouldMatch(int count) : base(count) { } diff --git a/src/Elastic.Clients.Elasticsearch/Common/ReadOnlyIndexNameDictionary.cs b/src/Elastic.Clients.Elasticsearch/Common/ReadOnlyIndexNameDictionary.cs new file mode 100644 index 00000000000..5bcdc9abd9b --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Common/ReadOnlyIndexNameDictionary.cs @@ -0,0 +1,61 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System.Collections; +using System.Collections.Generic; + +namespace Elastic.Clients.Elasticsearch +{ + /// + /// A specialised readonly dictionary for data, keyed by . + /// This supports inferrence enabled lookups by ensuring keys are sanitized when storing the values and when performing lookups. + /// + /// + public struct ReadOnlyIndexNameDictionary : IReadOnlyDictionary + { + private readonly Dictionary _backingDictionary; + private readonly IElasticsearchClientSettings? _settings; + + public ReadOnlyIndexNameDictionary() + { + _backingDictionary = new Dictionary(0); + _settings = null; + } + + internal ReadOnlyIndexNameDictionary(Dictionary source, IElasticsearchClientSettings settings) + { + _settings = settings; + + // This is an "optimised version" which doesn't cause a second dictionary to be allocated. + // Since we expect this to be used only for deserialisation, the keys received will already have been strings, + // so no further sanitisation is required. + + //var backingDictionary = new Dictionary(source.Count); + + if (source == null) + { + _backingDictionary = new Dictionary(0); + return; + } + + //foreach (var key in source.Keys) + // backingDictionary[Sanitize(key)] = source[key]; + + _backingDictionary = source; + } + + private string Sanitize(IndexName key) => _settings is not null ? key?.GetString(_settings) : string.Empty; + + public TValue this[IndexName key] => _backingDictionary.TryGetValue(Sanitize(key), out var v) ? v : default; + public TValue this[string key] => _backingDictionary.TryGetValue(key, out var v) ? v : default; + + public IEnumerable Keys => _backingDictionary.Keys; + public IEnumerable Values => _backingDictionary.Values; + public int Count => _backingDictionary.Count; + public bool ContainsKey(IndexName key) => _backingDictionary.ContainsKey(Sanitize(key)); + public IEnumerator> GetEnumerator() => _backingDictionary.GetEnumerator(); + public bool TryGetValue(IndexName key, out TValue value) => _backingDictionary.TryGetValue(Sanitize(key), out value); + IEnumerator IEnumerable.GetEnumerator() => _backingDictionary.GetEnumerator(); + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Request/IProxyRequest.cs b/src/Elastic.Clients.Elasticsearch/Common/Request/IProxyRequest.cs index a1d6bf88683..e410f702cba 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Request/IProxyRequest.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Request/IProxyRequest.cs @@ -7,7 +7,7 @@ namespace Elastic.Clients.Elasticsearch { - public interface ICustomJsonWriter + internal interface ICustomJsonWriter { // TODO: Temp //void WriteJson(Stream stream, ITransportSerializer sourceSerializer, SerializationFormatting formatting); diff --git a/src/Elastic.Clients.Elasticsearch/Common/Request/PlainRequestBase.cs b/src/Elastic.Clients.Elasticsearch/Common/Request/PlainRequestBase.cs new file mode 100644 index 00000000000..65deaf40caf --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/Common/Request/PlainRequestBase.cs @@ -0,0 +1,143 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + + +namespace Elastic.Clients.Elasticsearch +{ + //public readonly partial struct PropertyName : IDictionaryKey + //{ + // public string Key => Value; + //} + + //// This is an incomplete stub implementation and should really be a struct + //public partial class Indices : IUrlParameter + //{ + // public static readonly Indices All = new("_all"); + + // internal Indices(IndexName index) => _indexNameList.Add(index); + + // public Indices(IEnumerable indices) + // { + // indices.ThrowIfEmpty(nameof(indices)); + // _indexNameList.AddRange(indices); + // } + + // public Indices(IEnumerable indices) + // { + // indices.ThrowIfEmpty(nameof(indices)); + // _indexNameList.AddRange(indices.Select(s => (IndexName)s)); + // } + + // public IReadOnlyCollection Values => _indexNameList.ToArray(); + + // public static Indices Parse(string names) => names.IsNullOrEmptyCommaSeparatedList(out var list) ? null : new Indices(list); + + // public static Indices Single(string index) => new Indices((IndexName)index); + + // public static implicit operator Indices(string names) => Parse(names); + + // string IUrlParameter.GetString(ITransportConfiguration? settings) + // { + // if (settings is not IElasticsearchClientSettings elasticsearchClientSettings) + // throw new Exception( + // "Tried to pass index names on query sting but it could not be resolved because no Elastic.Clients.Elasticsearch settings are available."); + + // var indices = _indexNameList.Select(i => i.GetString(settings)).Distinct(); + + // return string.Join(",", indices); + // } + //} + + //public partial struct IndicesList : IUrlParameter + //{ + // //public static readonly IndicesList All = new("_all"); + + // private readonly List _indices = new(); + + // internal IndicesList(IndexName index) => _indices.Add(index); + + // public IndicesList(IEnumerable indices) + // { + // indices.ThrowIfEmpty(nameof(indices)); + + // // De-duplicating during creation avoids cost when accessing the values. + // foreach (var index in indices) + // if (!_indices.Contains(index)) + // _indices.Add(index); + // } + + // public IndicesList(string[] indices) + // { + // indices.ThrowIfEmpty(nameof(indices)); + + // foreach (var index in indices) + // if (!_indices.Contains(index)) + // _indices.Add(index); + // } + + // public IReadOnlyCollection Values => _indices; + + // public static IndicesList Parse(string names) => names.IsNullOrEmptyCommaSeparatedList(out var list) ? null : new IndicesList(list); + + // public static implicit operator IndicesList(string names) => Parse(names); + //} + + //public partial struct IndicesList { string IUrlParameter.GetString(ITransportConfiguration? settings) => ""; } + + + public abstract partial class PlainRequestBase + { + ///Include the stack trace of returned errors. + [JsonIgnore] + public bool? ErrorTrace + { + get => Q("error_trace"); + set => Q("error_trace", value); + } + + /// + /// A comma-separated list of filters used to reduce the response. + /// + /// Use of response filtering can result in a response from Elasticsearch + /// that cannot be correctly deserialized to the respective response type for the request. + /// In such situations, use the low level client to issue the request and handle response deserialization. + /// + /// + [JsonIgnore] + public string[] FilterPath + { + get => Q("filter_path"); + set => Q("filter_path", value); + } + + ///Return human readable values for statistics. + [JsonIgnore] + public bool? Human + { + get => Q("human"); + set => Q("human", value); + } + + ///Pretty format the returned JSON response. + [JsonIgnore] + public bool? Pretty + { + get => Q("pretty"); + set => Q("pretty", value); + } + + /// + /// The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST + /// requests. + /// + [JsonIgnore] + public string SourceQueryString + { + get => Q("source"); + set => Q("source", value); + } + } +} diff --git a/src/Elastic.Clients.Elasticsearch/Common/Request/RouteValues.cs b/src/Elastic.Clients.Elasticsearch/Common/Request/RouteValues.cs index aafc9bd6230..7d88ea4b01b 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/Request/RouteValues.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/Request/RouteValues.cs @@ -15,7 +15,7 @@ internal class ResolvedRouteValues : Dictionary public ResolvedRouteValues(int size) : base(size) { } } - public class RouteValues : Dictionary + public sealed class RouteValues : Dictionary { /// /// Used specifically by index requests to determine whether to use PUT or POST. diff --git a/src/Elastic.Clients.Elasticsearch/Common/TaggedUnion.cs b/src/Elastic.Clients.Elasticsearch/Common/TaggedUnion.cs deleted file mode 100644 index 334e0079201..00000000000 --- a/src/Elastic.Clients.Elasticsearch/Common/TaggedUnion.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Licensed to Elasticsearch B.V under one or more agreements. -// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -using System; - -namespace Elastic.Clients.Elasticsearch; - -public interface ITaggedUnion -{ - public abstract string Type { get; } - - public abstract T Value { get; } - - public bool Is(string type); -} - -public class TaggedUnionUtils -{ - public static T Get(TUnion union, string type) where TUnion : ITaggedUnion - { - if (union.Is(type)) - return union.Value; - - throw new InvalidCastException("TODO"); - } -} - -public interface IUnionVariant -{ - /// - /// Get the type of this object when used as a variant. - /// - string VariantType { get; } -} - -//public interface IContainer { } - -//public abstract class ContainerBase : IContainer -//{ -// internal void WrapInContainer(IContainer container) => InternalWrapInContainer(container); - -// internal abstract void InternalWrapInContainer(IContainer container); -//} diff --git a/src/Elastic.Clients.Elasticsearch/Common/TextToAnalyze.cs b/src/Elastic.Clients.Elasticsearch/Common/TextToAnalyze.cs deleted file mode 100644 index dd080674b4e..00000000000 --- a/src/Elastic.Clients.Elasticsearch/Common/TextToAnalyze.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to Elasticsearch B.V under one or more agreements. -// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -namespace Elastic.Clients.Elasticsearch.IndexManagement.Analyze -{ - //public partial class TextToAnalyze - //{ - // // This is temporary - // public TextToAnalyze(IEnumerable toAnalyze) => _stringList.AddRange(toAnalyze); - - // public string GetString(ITransportConfiguration settings) => throw new NotImplementedException(); - //} -} diff --git a/src/Elastic.Clients.Elasticsearch/Common/TimeUnit/Time.cs b/src/Elastic.Clients.Elasticsearch/Common/TimeUnit/Time.cs index 553eb2aabf6..9d7fd801f50 100644 --- a/src/Elastic.Clients.Elasticsearch/Common/TimeUnit/Time.cs +++ b/src/Elastic.Clients.Elasticsearch/Common/TimeUnit/Time.cs @@ -15,7 +15,7 @@ namespace Elastic.Clients.Elasticsearch; /// Represents a time value /// [JsonConverter(typeof(TimeConverter))] -public class Time : IComparable