Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Multi Terms Aggregation has no option to add missing field value. #973

Open
kushagra-palod opened this issue May 7, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@kushagra-palod
Copy link

Multiterms Aggregation builder takes a MultiTermsLookUp List as the parameter for terms which has a field function but if the field value is missing for that field, the data is not retuned. Basically there is no missing function which exixts for Terms Aggregation Builder.

A function eaxctly like which is present for TermsAggregation Builder would solve the problem I suppose,
TermsAggregatio Builder has a method to add missing field value but no such method appears to Exist for MultiTerms. Java docs link.
I've tried to use Terms Aggregation Builder but that only takes on field at a time but I want to use multiple terms.

List<MultiTermLookup> termLookupList = new ArrayList<>();
        termLookupList.add(new MultiTermLookup.Builder().field("sample.id").build());
        termLookupList.add(new MultiTermLookup.Builder().field("sample.name").build());
        termLookupList.add(new MultiTermLookup.Builder().field("sample.mediaCode").build());
        MultiTermsAggregation multiTermsAggregation = new MultiTermsAggregation.Builder()
                .terms(termLookupList)
                .size(10000)
                .build();

This is the way I am using the multi terms aggregation. But when the 'mediacode' field is missing for a particular document. That creates a problem and data is not returned for that document.
I am further using the multiTerms aggregation to do some calculations like this. :

FieldSort fieldSort = new FieldSort.Builder()
                .field("aggregatedValue")
                .order(SortOrder.Desc)
                .build();
        SortOptions sortOptions = new SortOptions.Builder()
                .field(fieldSort)
                .build();
        BucketSortAggregation sortAggregation = new BucketSortAggregation.Builder()
                .sort(sortOptions)
                .size(10)
                .build();
        Aggregation aggregationForSum = new Aggregation.Builder().sum(sumAggregation).build();
        Aggregation aggregationForReverseNesting = new Aggregation.Builder().reverseNested(reverseNestedAggregation).build();
        Aggregation aggregationForBucketSort = new Aggregation.Builder().bucketSort(sortAggregation).build();
        Aggregation rankingAggregation = new Aggregation.Builder()
                .multiTerms(multiTermsAggregation)
                .aggregations("missing",aggregationForMissing)
                .aggregations("aggregatedValue",aggregationForSum)
                .aggregations("dealCount",aggregationForReverseNesting)
                .aggregations("aggregatedValue_bucket_sort",aggregationForBucketSort)
                .build();

I have also tried using MissingAggregation Builder but that does not seem to work with multiterms when I'm adding that in my ranking aggregation.

@kushagra-palod kushagra-palod added enhancement New feature or request untriaged labels May 7, 2024
@dblock dblock removed the untriaged label May 16, 2024
@HabooshHaddad
Copy link

Hello,
Is this going to be fixed soon ?

@Xtansia
Copy link
Collaborator

Xtansia commented Sep 29, 2024

I'm not sure that multi_terms supports a missing parameter on OpenSearch itself: https://opensearch.org/docs/latest/aggregations/bucket/multi-terms/

Do you have a query you've used on the OpenSearch Dashboards Dev Tools that does work as expected?

@Xtansia
Copy link
Collaborator

Xtansia commented Sep 29, 2024

If not then it would be worth opening a feature request on https://github.com/opensearch-project/OpenSearch

@kushagra-palod
Copy link
Author

Yes I do have sample on dev tools where I used multi terms aggregation with a missing parameter.

"aggregations": {
            "ranking": {
              "multi_terms": {
                "terms": [
                  {
                    "field": "sampleField.id"
                  },
                  {
                    "field": "sampleField.name",
                    "missing": ""
                  },
                  {
                    "field": "sampleField.mediaCode",
                    "missing": ""
                  }
                ],
                "size": 10000
              }

Here simply If the name or mediacode field was missing it was replaced with an empty string. But if I removed the missing parameter, the data was skipped for aggregation if one of the field for it did not exist.

@kushagra-palod
Copy link
Author

Elastic search API reference:
MultiTermsAggregation.Builder, The terms take a type of MultiTermLookup value which has the missing parameter in its builder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants