Elasticsearch "must" 查询不是索引的映射

Elasticsearch "must" query isn't mapping of index

我没有在 elasticsearch 中使用 must 运算符查询 .net core。我使用 .net 5、Elasticsearch 7.16.0、NEST 7.16.0。

BeginDate = BeginDate == null ? DateTime.Parse("01/01/1900") : BeginDate;
        EndDate = EndDate == null ? DateTime.Now : EndDate;
        var response = _client.Search<LogModel>(s => s
       .From(page)
       .Size(rowCount)
       .Sort(ss => ss.Descending(p => p.PostDate))
       .Query(q => q
           .Bool(b => b
               .Must(
                   q => q.Term(t => t.LogType, "INFO"),
                   q => q.Term(t => t.RegionCode, RegionCode),
                   q => q.DateRange(dr => dr
                   .Field(p => p.PostDate)
                   .GreaterThanOrEquals(DateMath.Anchored(((DateTime)BeginDate).AddDays(-1)))
                   .LessThanOrEquals(DateMath.Anchored(((DateTime)EndDate).AddDays(1)))
                   ))
                )
             )
       .Index(indexName)
       );
        return response.Documents;

如果您想使用 Term 查询,您实际上需要在 keyword 子字段上 运行 它们,如下所示:

...
q => q.Term(t => t.LogType.Suffix("keyword"), "INFO"),
q => q.Term(t => t.RegionCode.Suffix("keyword"), RegionCode),
...