1

Here is a DSL query I wrote from the front side; however, since we need to update the arch, we must query from the 'c#' side.

{
  "query": {
    "query_string": {
      "fields": [
        "siteId"
      ],
      "query": "SE0*"
    }
  },
  "aggs": {
    "total": {
      "cardinality": {
        "field": "linkId.keyword"
      }
    },
    "los_counts": {
      "terms": {
        "field": "linkId.keyword",
        "size": "10000"
      },
      "aggs": {
        "los": {
          "filters": {
            "filters": {
              "los_true": {
                "match": {
                  "losFlag": "Y"
                }
              },
              "los_false": {
                "bool": {
                  "must_not": {
                    "match": {
                      "losFlag": "Y"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "collapse": {
    "field": "linkId.keyword"
  }
}

for the aforementioned DSL client side's payload query, to which I tested the following NEST elastic client 'c#' query.

    await _elasticClient.SearchAsync<T>(s => s
                                 .Index(indexName)
                                 .Take(10000)
                                 .Query(q => (q
                                          .MultiMatch(m => m
                                          .Fields(["siteId"])
                                          .Query("SE0")
                                           )))
                                 .Aggregations(ag => ag
                                    .Cardinality("total", ca => ca.Field("linkId.keyword"))
                                    .Terms("los_counts",tr=>tr.Field("linkId.keyword")
                                    .Aggregations(agg=>agg.Filters("los",fi=>fi.)) 
                                    /*  */
                                    )
                                    )
    
                                 .Collapse(col => col.Field("linkId.keyword"))
                                 ).ConfigureAwait(false);

I was caught at the comment area and was unable to access the "filters" inside of the "filters" once again. then, how do we convert here?

1 Answer 1

1

Try this Filters Aggregation

.Aggregations(agg => agg.Filters("projects_by_state",
                     agg => agg.NamedFilters(filters => filters                                                                                  
                                           .Filter("los_true", f => f.Match(p =>p.Field("losFlag").Query("Y")))                                                                                  
                                           .Filter("los_false", f =>f.Bool(p=>p.MustNot(b=>b.Match(p => p.Field("losFlag").Query("Y")))))
                                                                         )
                                                                    )
                                              )
Sign up to request clarification or add additional context in comments.

2 Comments

got an error "System.ArgumentException: ''total' is one of the reserved aggregation keywords we use a heuristics based response parser and using these reserved keywords could throw its heuristics off course. We are working on a solution in Elasticsearch itself to make the response parseable. For now these are all the reserved, so I sending it as "total.keyword" then getting "No Data found" exception
can u add full query , along with sample data to replicate

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.