Calculate the similarity between two fields same doc

Hello, I trying during log ingestion calculate the percentage of similarity between two fields. For example, A=foobar B=barfoor

I have read about this here: similarity | Elasticsearch Guide [8.15] | Elastic

But I dont knwo how apply it, maybe with a script processor in ingest-pipeline.

Thanks
Diego