Fingerprint processor

Introduced 2.16

The fingerprint processor is used to generate a hash value for either certain specified fields or all fields in a document. The hash value can be used to deduplicate documents within an index and collapse search results.

For each field, the field name, the length of the field value, and the field value itself are concatenated and separated by the pipe character |. For example, if the field name is field1 and the value is value1, then the concatenated string would be |field1|3:value1|field2|10:value2|. For object fields, the field name is flattened by joining the nested field names with a period .. For instance, if the object field is root_field with a sub-field sub_field1 having the value value1 and another sub-field sub_field2 with the value value2, then the concatenated string would be |root_field.sub_field1|1:value1|root_field.sub_field2|100:value2|.

The following is the syntax for the fingerprint processor:

  1. {
  2. "community_id": {
  3. "fields": ["foo", "bar"],
  4. "target_field": "fingerprint",
  5. "hash_method": "SHA-1@2.16.0"
  6. }
  7. }

copy

Configuration parameters

The following table lists the required and optional parameters for the fingerprint processor.

ParameterRequired/OptionalDescription
fieldsOptionalA list of fields used to generate a hash value.
exclude_fieldsOptionalSpecifies the fields to be excluded from hash value generation. It is mutually exclusive with the fields parameter; if both exclude_fields and fields are empty or null, then all fields are included in the hash value calculation.
hash_methodOptionalSpecifies the hashing algorithm to be used, with options being MD5@2.16.0, SHA-1@2.16.0, SHA-256@2.16.0, or SHA3-256@2.16.0. Default is SHA-1@2.16.0. The version number is appended to ensure consistent hashing across OpenSearch versions, and new versions will support new hash methods.
target_fieldOptionalSpecifies the name of the field in which the generated hash value will be stored. If not provided, then the hash value is stored in the fingerprint field by default.
ignore_missingOptionalSpecifies whether the processor should exit quietly if one of the required fields is missing. Default is false.
descriptionOptionalA brief description of the processor.
ifOptionalA condition for running the processor.
ignore_failureOptionalIf set to true, then failures are ignored. Default is false.
on_failureOptionalA list of processors to run if the processor fails.
tagOptionalAn identifier tag for the processor. Useful for debugging in order to distinguish between processors of the same type.

Using the processor

Follow these steps to use the processor in a pipeline.

Step 1: Create a pipeline

The following query creates a pipeline named fingerprint_pipeline that uses the fingerprint processor to generate a hash value for specified fields in the document:

  1. PUT /_ingest/pipeline/fingerprint_pipeline
  2. {
  3. "description": "generate hash value for some specified fields the document",
  4. "processors": [
  5. {
  6. "fingerprint": {
  7. "fields": ["foo", "bar"]
  8. }
  9. }
  10. ]
  11. }

copy

Step 2 (Optional): Test the pipeline

It is recommended that you test your pipeline before ingesting documents.

To test the pipeline, run the following query:

  1. POST _ingest/pipeline/fingerprint_pipeline/_simulate
  2. {
  3. "docs": [
  4. {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source": {
  8. "foo": "foo",
  9. "bar": "bar"
  10. }
  11. }
  12. ]
  13. }

copy

Response

The following example response confirms that the pipeline is working as expected:

  1. {
  2. "docs": [
  3. {
  4. "doc": {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source": {
  8. "foo": "foo",
  9. "bar": "bar",
  10. "fingerprint": "SHA-1@2.16.0:fYeen7hTJ2zs9lpmUnk6nvH54sM="
  11. },
  12. "_ingest": {
  13. "timestamp": "2024-03-11T02:17:22.329823Z"
  14. }
  15. }
  16. }
  17. ]
  18. }

Step 3: Ingest a document

The following query ingests a document into an index named testindex1:

  1. PUT testindex1/_doc/1?pipeline=fingerprint_pipeline
  2. {
  3. "foo": "foo",
  4. "bar": "bar"
  5. }

copy

Response

The request indexes the document into the testindex1 index:

  1. {
  2. "_index": "testindex1",
  3. "_id": "1",
  4. "_version": 1,
  5. "result": "created",
  6. "_shards": {
  7. "total": 2,
  8. "successful": 1,
  9. "failed": 0
  10. },
  11. "_seq_no": 0,
  12. "_primary_term": 1
  13. }

Step 4 (Optional): Retrieve the document

To retrieve the document, run the following query:

  1. GET testindex1/_doc/1

copy