Skip to content

Commit 80d1449

Browse files
committed
Support resource_name on AttachmentProcessor
Contributes to #5198 Relates to elastic/elasticsearch#64389
1 parent f78d25d commit 80d1449

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,39 @@ public class Attachment : ProcessorAssertion
451451
public override string Key => "attachment";
452452
}
453453

454+
[SkipVersion("<7.11.0", "Resource name support was added in 7.11")]
455+
public class Attachment_WithResourceName : ProcessorAssertion
456+
{
457+
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent => d => d
458+
.Attachment<Project>(ud => ud
459+
.Field(p => p.Description)
460+
.IndexedCharacters(100_000)
461+
.Properties("title", "author")
462+
.IgnoreMissing()
463+
.ResourceName(n => n.Name)
464+
);
465+
466+
public override IProcessor Initializer => new AttachmentProcessor
467+
{
468+
Field = "description",
469+
Properties = new[] { "title", "author" },
470+
IndexedCharacters = 100_000,
471+
IgnoreMissing = true,
472+
ResourceName = "name"
473+
};
474+
475+
public override object Json => new
476+
{
477+
field = "description",
478+
ignore_missing = true,
479+
properties = new[] { "title", "author" },
480+
indexed_chars = 100_000,
481+
resource_name = "name"
482+
};
483+
484+
public override string Key => "attachment";
485+
}
486+
454487
[SkipVersion("<7.4.0", "Circle processor added in 7.4.0")]
455488
public class Circle : ProcessorAssertion
456489
{

0 commit comments

Comments
 (0)