1

I'm trying to run the following Filter Aggregation query against ElasticSearch via Nest 2.3.2.

GET workitems_v2/mail/_search
{
  size:0,
  "aggs" : {
    "AutoComplete" : {
      "filter" : { "match": { "claimData.claimOwner":"dav" } },
      "aggs": {
        "Suggestions": {
          "terms": {"field":"claimData.claimOwner.raw"}
        }
      }
    }
  }
}

Here's what I have in Nest (VB.Net) - note how the second Aggregations() function is a child of the Filter() function.

Dim queryResults = elasticClient.Search(Of Mail)(Function(s) s.
    Size(0).
    Aggregations(Function(a) a.
        Filter("AutoComplete", Function(f) f.
            Filter(Function(ff) ff.
                Match(Function(m) m.
                    Field("claimData.claimOwner").
                    Query("dav")
                )
            ).
            Aggregations(Function(aa) a.
                Terms("Suggestions", Function(t) t.
                    Field("claimData.claimOwner.raw")
                )
            )
        )
    )
)

But the query that Nest generates looks like:

POST /workitems_v2/mail/_search
{
    "size" : 0,
    "aggs" : {
        "Suggestions" : {
            "terms" : {
                "field" : "claimData.claimOwner.raw"
            }
        },
        "AutoComplete" : {
            "filter" : {
                "match" : {
                    "claimData.claimOwner" : {
                        "query" : "dav"
                    }
                }
            }
        }
    }
}

... which doesn't give me what I want. How do I tell Nest that the "Suggestions" aggregation is part of the first Filter Aggregation?

1 Answer 1

2

Your query is not quite correct; the sub aggregation should be using the AggregationContainerDescriptor<T> passed as the argument for aa in the anonymous function

Dim queryResults = elasticClient.Search(Of Mail)(Function(s) s.
Size(0).
Aggregations(Function(a) a.
    Filter("AutoComplete", Function(f) f.
        Filter(Function(ff) ff.
            Match(Function(m) m.
                Field("claimData.claimOwner").
                Query("dav")
            )
        ).
        Aggregations(Function(aa) aa.
            Terms("Suggestions", Function(t) t.
                Field("claimData.claimOwner.raw")
            )
        )
    )
)

which results in

{
  "size": 0,
  "aggs": {
    "AutoComplete": {
      "filter": {
        "match": {
          "claimData.claimOwner": {
            "query": "dav"
          }
        }
      },
      "aggs": {
        "Suggestions": {
          "terms": {
            "field": "claimData.claimOwner.raw"
          }
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.