本文主要为您介绍嵌套类型查询相关接口。

NestedQuery

NestedQuery用于嵌套类型的查询。嵌套类型不能直接查询,需要通过NestedQuery来包装一下,NestedQuery中需要指定嵌套类型的字段路径(path)以及一个子query(可以是任意query)。

示例:
/// <summary>
/// 有一个类型为NESTED的列,子文档包含nested_1和nested_2两列,现在查询col1_nested.nested_1为"tablestore"的数据
/// </summary>
/// <param name="otsClient"></param>
public static void NestedQuery(OTSClient otsClient)
{
    var searchQuery = new SearchQuery();
    searchQuery.GetTotalCount = true;
    var nestedQuery = new NestedQuery();
    nestedQuery.Path = "col1_nested"; //设置nested字段路径
    TermQuery termQuery = new TermQuery("col1_nested.nested_1",new ColumnValue("tablestore"));//构造NestedQuery的子查询
    nestedQuery.Query = termQuery;
    nestedQuery.ScoreMode = ScoreMode.None;

    var request = new SearchRequest(TableName, IndexName, searchQuery);
    request.ColumnsToGet = new ColumnsToGet()
    {
        ReturnAll = true
    };

    var response = otsClient.Search(request);

    Console.WriteLine("Total Count:" + response.TotalCount);
}