Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get min/max and avg lengths of text field?

I have an index with the following mapping:

        "properties": {
            "content": {
                "type":  "text",                
            },
            "ar_name": {
                "type": "text"
            }

        }

I want to get statistics (min length, max length and average length) to the content
field.

How can I do it ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The string_stats aggregation provides that support but only for keyword fields. Since your content field is of type text, I assume it contains free-text that is not really suitable as keyword.

If that’s the case, I would suggest that you stored the length of the content field in another integer field (e.g. content_length) that you can then use in a stats aggregation that would return you the metrics you expect.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading