Skip to content

Commit c892391

Browse files
authored
Support resource_name on AttachmentProcessor (#5205)
Contributes to #5198 Relates to elastic/elasticsearch#64389
1 parent f42bfa4 commit c892391

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/Nest/Ingest/Processors/Plugins/AttachmentProcessor.cs

+21-5
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace Nest
2121
[InterfaceDataContract]
2222
public interface IAttachmentProcessor : IProcessor
2323
{
24-
/// <summary> The field to get the base64 encoded field from </summary>
24+
/// <summary> The field to get the base64 encoded field from.</summary>
2525
[DataMember(Name ="field")]
2626
Field Field { get; set; }
2727

2828

29-
/// <summary> If `true` and `field` does not exist, the processor quietly exits without modifying the document </summary>
29+
/// <summary> If `true` and `field` does not exist, the processor quietly exits without modifying the document.</summary>
3030
[DataMember(Name ="ignore_missing")]
3131
bool? IgnoreMissing { get; set; }
3232

@@ -37,20 +37,26 @@ public interface IAttachmentProcessor : IProcessor
3737
[DataMember(Name ="indexed_chars")]
3838
long? IndexedCharacters { get; set; }
3939

40-
/// <summary> Field name from which you can overwrite the number of chars being used for extraction. </summary>
40+
/// <summary> Field name from which you can overwrite the number of chars being used for extraction.</summary>
4141
[DataMember(Name ="indexed_chars_field")]
4242
Field IndexedCharactersField { get; set; }
4343

4444
/// <summary>
4545
/// Properties to select to be stored. Can be content, title, name, author,
46-
/// keywords, date, content_type, content_length, language. Defaults to all
46+
/// keywords, date, content_type, content_length, language. Defaults to all.
4747
/// </summary>
4848
[DataMember(Name ="properties")]
4949
IEnumerable<string> Properties { get; set; }
5050

51-
/// <summary> The field that will hold the attachment information </summary>
51+
/// <summary> The field that will hold the attachment information.</summary>
5252
[DataMember(Name ="target_field")]
5353
Field TargetField { get; set; }
54+
55+
/// <summary> The field containing the name of the resource to decode.
56+
/// If specified, the processor passes this resource name to the underlying
57+
/// Tika library to enable 'Resource Name Based Detection'.</summary>
58+
[DataMember(Name = "resource_name")]
59+
Field ResourceName { get; set; }
5460
}
5561

5662
/// <inheritdoc cref="IAttachmentProcessor" />
@@ -75,6 +81,9 @@ public class AttachmentProcessor : ProcessorBase, IAttachmentProcessor
7581
/// <inheritdoc cref="IAttachmentProcessor.TargetField" />
7682
public Field TargetField { get; set; }
7783

84+
/// <inheritdoc cref="IAttachmentProcessor.ResourceName" />
85+
public Field ResourceName { get; set; }
86+
7887
protected override string Name => "attachment";
7988
}
8089

@@ -91,6 +100,7 @@ public class AttachmentProcessorDescriptor<T>
91100
Field IAttachmentProcessor.IndexedCharactersField { get; set; }
92101
IEnumerable<string> IAttachmentProcessor.Properties { get; set; }
93102
Field IAttachmentProcessor.TargetField { get; set; }
103+
Field IAttachmentProcessor.ResourceName { get; set; }
94104

95105
/// <inheritdoc cref="IAttachmentProcessor.Field" />
96106
public AttachmentProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
@@ -122,5 +132,11 @@ public AttachmentProcessorDescriptor<T> IndexedCharactersField<TValue>(Expressio
122132

123133
/// <inheritdoc cref="IAttachmentProcessor.Properties" />
124134
public AttachmentProcessorDescriptor<T> Properties(params string[] properties) => Assign(properties, (a, v) => a.Properties = v);
135+
136+
/// <inheritdoc cref="IAttachmentProcessor.ResourceName" />
137+
public AttachmentProcessorDescriptor<T> ResourceName(Field field) => Assign(field, (a, v) => a.ResourceName = v);
138+
139+
/// <inheritdoc cref="IAttachmentProcessor.TargetField" />
140+
public AttachmentProcessorDescriptor<T> ResourceName<TValue>(Expression<Func<T, TValue>> objectPath) => Assign(objectPath, (a, v) => a.ResourceName = v);
125141
}
126142
}

tests/Tests/Ingest/ProcessorAssertions.cs

+33
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,39 @@ public class Attachment : ProcessorAssertion
463463
public override string Key => "attachment";
464464
}
465465

466+
[SkipVersion("<7.11.0", "Resource name support was added in 7.11")]
467+
public class Attachment_WithResourceName : ProcessorAssertion
468+
{
469+
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent => d => d
470+
.Attachment<Project>(ud => ud
471+
.Field(p => p.Description)
472+
.IndexedCharacters(100_000)
473+
.Properties("title", "author")
474+
.IgnoreMissing()
475+
.ResourceName(n => n.Name)
476+
);
477+
478+
public override IProcessor Initializer => new AttachmentProcessor
479+
{
480+
Field = "description",
481+
Properties = new[] { "title", "author" },
482+
IndexedCharacters = 100_000,
483+
IgnoreMissing = true,
484+
ResourceName = "name"
485+
};
486+
487+
public override object Json => new
488+
{
489+
field = "description",
490+
ignore_missing = true,
491+
properties = new[] { "title", "author" },
492+
indexed_chars = 100_000,
493+
resource_name = "name"
494+
};
495+
496+
public override string Key => "attachment";
497+
}
498+
466499
[SkipVersion("<7.4.0", "Circle processor added in 7.4.0")]
467500
public class Circle : ProcessorAssertion
468501
{

0 commit comments

Comments
 (0)