NEST:创建别名并设置过滤器

问题描述 投票:0回答:1

我对ES非常陌生。在探索用于.Net的NEST客户端时,我遇到了无法解决如何使用NEST.Net的情况。

配置:.Net 4.6.1NEST 7.2.0

我正在尝试在现有索引上设置别名。我能够使用以下方法实现它。

await _client.Indices.PutAliasAsync(indexName, aliasName);

尽管别名为空,这会在索引上创建别名。

现在我想实现以下结构。

"MyIndexName" : {
    "aliases" : {
      "MyAliasName" : {
        "filter" : {
          "term" : {
            "MyFilterTerm" : "MyFilterTermValue"
          }
        }
      },
}

我在以下代码段中使用过

await _client.Indices.PutAliasAsync(indexName, aliasName,
                                a => a.Filter<MyTestClass>(
                                    f => f.Term("MyFilterTerm", "MyFilterTermValue")));

public class MyTestClass {// not sure what this was supposed to be}

但是这会产生如下的json。

"MyIndexName" : {
    "aliases" : {
      "MyAliasName" : {
        "filter" : {
          "term" : {
            "MyFilterTerm" : {
              "value" : "MyFilterTermValue"
            }
          }
        }
      },
}

如何实现第一种JSON格式?

c# .net elasticsearch nest
1个回答
0
投票

term子句中用于filter查询的两种JSON格式是等效的。 NEST通常会发出更长的查询形式,对于term query

"term" : {
    "<field>" : {
        "value" : "<value>"
    }
}

相对于简短形式

"term" : {
    "<field>" : "<value>"
}
© www.soinside.com 2019 - 2024. All rights reserved.