Skip to content

Commit

Permalink
Added aggregation validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Sep 3, 2024
1 parent ef4acd5 commit 780342d
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,22 @@ private async Task<string> GetIncludeAsync(string name)
await Task.Delay(150);
return "included:value";
}

[Fact]
public async Task CanValidateAggregation()
{
var index = CreateRandomIndex<MyType>(d => d.Properties(p => p.Keyword(e => e.Name(m => m.Field1))));
await Client.IndexAsync(new MyType { Field1 = "value123" }, i => i.Index(index));
await Client.Indices.RefreshAsync(index);

var context = new ElasticQueryVisitorContext { QueryType = QueryTypes.Aggregation };
var parser = new ElasticQueryParser(c => c.UseMappings(Client, index).SetValidationOptions(new QueryValidationOptions { AllowUnresolvedFields = false, }).SetLoggerFactory(Log));
var node = await parser.ParseAsync("terms:(id~100 @missing:__missing__)", context);

var result = await ValidationVisitor.RunAsync(node, context);
Assert.True(result.IsValid, result.Message);
Assert.Single(result.ReferencedFields, "field1");
}
}

public class MyType
Expand Down

0 comments on commit 780342d

Please sign in to comment.