/* 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.Linq.Expressions;
using System.Runtime.Serialization;
using OpenSearch.Net.Utf8Json;
namespace OpenSearch.Client.Specification.IngestApi
{
///
/// Similar to the Grok Processor, dissect also extracts structured fields out of a single text field
/// within a document. However unlike the Grok Processor, dissect does not use Regular Expressions.
/// This allows dissect’s syntax to be simple and, for some cases faster, than the Grok Processor.
///
[InterfaceDataContract]
public interface IDissectProcessor : IProcessor
{
/// The field to dissect
[DataMember(Name = "field")]
Field Field { get; set; }
/// The pattern to apply to the field
[DataMember(Name = "pattern")]
string Pattern { get; set; }
///
/// If true and field does not exist or is null, the processor quietly exits without modifying the document
///
[DataMember(Name = "ignore_missing")]
bool? IgnoreMissing { get; set; }
/// The character(s) that separate the appended fields.
[DataMember(Name = "append_separator")]
string AppendSeparator { get; set; }
}
///
public class DissectProcessor : ProcessorBase, IDissectProcessor
{
protected override string Name => "dissect";
///
public Field Field { get; set; }
///
public string Pattern { get; set; }
///
public bool? IgnoreMissing { get; set; }
///
public string AppendSeparator { get; set; }
}
///
public class DissectProcessorDescriptor
: ProcessorDescriptorBase, IDissectProcessor>, IDissectProcessor
where T : class
{
protected override string Name => "dissect";
Field IDissectProcessor.Field { get; set; }
string IDissectProcessor.Pattern { get; set; }
bool? IDissectProcessor.IgnoreMissing { get; set; }
string IDissectProcessor.AppendSeparator { get; set; }
///
public DissectProcessorDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v);
///
public DissectProcessorDescriptor Field(Expression> objectPath) =>
Assign(objectPath, (a, v) => a.Field = v);
///
public DissectProcessorDescriptor Pattern(string pattern) =>
Assign(pattern, (a, v) => a.Pattern = v);
///
public DissectProcessorDescriptor IgnoreMissing(bool? traceMatch = true) =>
Assign(traceMatch, (a, v) => a.IgnoreMissing = v);
///
public DissectProcessorDescriptor AppendSeparator(string appendSeparator) =>
Assign(appendSeparator, (a, v) => a.AppendSeparator = v);
}
}