Adjacency Matrix Usageedit

Fluent DSL exampleedit

s => s
.Size(0)
.Aggregations(aggs => aggs
    .AdjacencyMatrix("interactions", am => am
        .Filters(fs => fs
            .Filter("grpA", f => f.Term(p => p.State, StateOfBeing.BellyUp))
            .Filter("grpB", f => f.Term(p => p.State, StateOfBeing.Stable))
            .Filter("grpC", f => f.Term(p => p.State, StateOfBeing.VeryActive))
        )
    )
)

Object Initializer syntax exampleedit

new SearchRequest<Project>
{
    Size =  0,
    Aggregations = new AdjacencyMatrixAggregation("interactions")
    {
        Filters = new NamedFiltersContainer
        {
            { "grpA", new TermQuery { Field = "state", Value = StateOfBeing.BellyUp } },
            { "grpB", new TermQuery { Field = "state", Value = StateOfBeing.Stable } },
            { "grpC", new TermQuery { Field = "state", Value = StateOfBeing.VeryActive } },
        }
    }
}

Example json output. 

{
  "size": 0,
  "aggs": {
    "interactions": {
      "adjacency_matrix": {
        "filters": {
          "grpA": {
            "term": {
              "state": {
                "value": "BellyUp"
              }
            }
          },
          "grpB": {
            "term": {
              "state": {
                "value": "Stable"
              }
            }
          },
          "grpC": {
            "term": {
              "state": {
                "value": "VeryActive"
              }
            }
          }
        }
      }
    }
  }
}

Handling Responsesedit

response.ShouldBeValid();
var interactions = response.Aggs.AdjacencyMatrix("interactions");
interactions.Should().NotBeNull();
var buckets = interactions.Buckets;
buckets.Should().NotBeNullOrEmpty();
foreach (var bucket in buckets)
{
    bucket.Key.Should().NotBeNullOrEmpty();
    bucket.DocCount.Should().BeGreaterThan(0);
}