简体   繁体   English

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

[英]NEST : Create Alias and set filter

I am very new to ES.我对 ES 很陌生。 While exploring NEST client for.Net I came across a situation which am not able to figure out how to achieve using NEST.Net.在探索 NEST 客户端 for.Net 时,我遇到了一种无法弄清楚如何使用 NEST.Net 实现的情况。

Configuration: .Net 4.6.1 NEST 7.2.0配置:.Net 4.6.1 NEST 7.2.0

What I am trying is to set an alias on an existing index.我正在尝试在现有索引上设置别名。 I was able to achieve it using following.我能够使用以下方法实现它。

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

This creates an alias on index though alias is empty.尽管别名为空,但这会在索引上创建一个别名。

Now I wanted to achieve below structure.现在我想实现以下结构。

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

I used below snippet我使用了下面的片段

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}

however this produces json as below.但是,这会产生如下 json。

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

How do I achieve the first JSON format?如何实现第一个 JSON 格式?

The two JSON formats for the term query in the filter clause are the equivalent. filter子句中term查询的两种 JSON 格式是等价的。 NEST typically emits the longer form of queries, which for a term query is NEST 通常会发出较长形式的查询,对于术语查询来说是

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

as opposed to the short form与缩写形式相反

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM