Skip to content

Commit 780342d

Browse files
committed
Added aggregation validation test
1 parent ef4acd5 commit 780342d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/Foundatio.Parsers.ElasticQueries.Tests/ElasticQueryParserTests.cs

+16
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,22 @@ private async Task<string> GetIncludeAsync(string name)
14941494
await Task.Delay(150);
14951495
return "included:value";
14961496
}
1497+
1498+
[Fact]
1499+
public async Task CanValidateAggregation()
1500+
{
1501+
var index = CreateRandomIndex<MyType>(d => d.Properties(p => p.Keyword(e => e.Name(m => m.Field1))));
1502+
await Client.IndexAsync(new MyType { Field1 = "value123" }, i => i.Index(index));
1503+
await Client.Indices.RefreshAsync(index);
1504+
1505+
var context = new ElasticQueryVisitorContext { QueryType = QueryTypes.Aggregation };
1506+
var parser = new ElasticQueryParser(c => c.UseMappings(Client, index).SetValidationOptions(new QueryValidationOptions { AllowUnresolvedFields = false, }).SetLoggerFactory(Log));
1507+
var node = await parser.ParseAsync("terms:(id~100 @missing:__missing__)", context);
1508+
1509+
var result = await ValidationVisitor.RunAsync(node, context);
1510+
Assert.True(result.IsValid, result.Message);
1511+
Assert.Single(result.ReferencedFields, "field1");
1512+
}
14971513
}
14981514

14991515
public class MyType

0 commit comments

Comments
 (0)