/* SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ /* * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. * * Licensed to Elasticsearch B.V. under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch B.V. licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ using System; using System.Runtime.Serialization; using OpenSearch.Net.Utf8Json; namespace OpenSearch.Client { [MapsApi("update.json")] public partial interface IUpdateRequest where TDocument : class where TPartialDocument : class { [DataMember(Name = "detect_noop")] bool? DetectNoop { get; set; } [DataMember(Name = "doc")] [JsonFormatter(typeof(SourceFormatter<>))] TPartialDocument Doc { get; set; } [DataMember(Name = "doc_as_upsert")] bool? DocAsUpsert { get; set; } [DataMember(Name = "script")] IScript Script { get; set; } /// /// If you would like your script to run regardless of whether the document exists or not — i.e. the script handles /// initializing the document instead of the upsert element — then set scripted_upsert to true /// [DataMember(Name = "scripted_upsert")] bool? ScriptedUpsert { get; set; } [DataMember(Name = "_source")] Union Source { get; set; } [DataMember(Name = "upsert")] [JsonFormatter(typeof(SourceFormatter<>))] TDocument Upsert { get; set; } } public partial class UpdateRequest where TDocument : class where TPartialDocument : class { /// public bool? DetectNoop { get; set; } /// public TPartialDocument Doc { get; set; } /// public bool? DocAsUpsert { get; set; } /// public IScript Script { get; set; } /// public bool? ScriptedUpsert { get; set; } /// public Union Source { get; set; } /// public TDocument Upsert { get; set; } } public partial class UpdateDescriptor where TDocument : class where TPartialDocument : class { bool? IUpdateRequest.DetectNoop { get; set; } TPartialDocument IUpdateRequest.Doc { get; set; } bool? IUpdateRequest.DocAsUpsert { get; set; } IScript IUpdateRequest.Script { get; set; } bool? IUpdateRequest.ScriptedUpsert { get; set; } Union IUpdateRequest.Source { get; set; } TDocument IUpdateRequest.Upsert { get; set; } /// /// The full document to be created if an existing document does not exist for a partial merge. /// public UpdateDescriptor Upsert(TDocument upsertObject) => Assign(upsertObject, (a, v) => a.Upsert = v); /// /// The partial update document to be merged on to the existing object. /// public UpdateDescriptor Doc(TPartialDocument @object) => Assign(@object, (a, v) => a.Doc = v); public UpdateDescriptor DocAsUpsert(bool? docAsUpsert = true) => Assign(docAsUpsert, (a, v) => a.DocAsUpsert = v); public UpdateDescriptor DetectNoop(bool? detectNoop = true) => Assign(detectNoop, (a, v) => a.DetectNoop = v); public UpdateDescriptor ScriptedUpsert(bool? scriptedUpsert = true) => Assign(scriptedUpsert, (a, v) => a.ScriptedUpsert = v); public UpdateDescriptor Script(Func scriptSelector) => Assign(scriptSelector, (a, v) => a.Script = v?.Invoke(new ScriptDescriptor())); public UpdateDescriptor Source(bool? enabled = true) => Assign(enabled, (a, v) => a.Source = v); public UpdateDescriptor Source(Func, ISourceFilter> selector) => Assign(selector, (a, v) => a.Source = new Union(v?.Invoke(new SourceFilterDescriptor()))); } }