Nest serialize elasticsearch术语查询请求

时间:2016-02-26 07:31:17

标签: nest

我使用NEST 2.0.2查询ElasticSearch。 非常好的API,感谢您的努力,但我认为需要文档更新。 反正,

  1. 我想序列化我的请求。我找不到任何信息,有一些stackoverflow问题,但它关于旧版本,并且api已更改。
  2. 我想写一个"术语查询"。但是没能成功。
  3. 工作意义DSL在下面。

    GET myindex/mytype/_search?search_type=count
    {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "field1": {
                  "value": 2
                }
              }
            }
          ],
          "must_not": [
            {
              "terms": {
                "field2": [
                  16,
                  17,
                  18,
                  19
                ]
              }
            }
          ]
        }
      },
      "aggs": {
        "termsAggField2": {
          "terms": {
            "field": "field2",
            "size": 20
          },
          "aggs": {
            "sumAggField3": {
              "sum": {
                "field": "field3"
              }
            }
          }
        }
      }
    }
    

    条款查询代码如下。 DSL在某种意义上起作用,但查询不起作用。 "不在"不过滤输出。

    List<QueryContainer> must_not = new List<QueryContainer>();
    
    must_not.Add(Query<mytype>.Terms(trms => trms.Terms(new string[] { "16", "17", "18", "19" })));
    
    var resultTermsSum = b1.ElasticClient.Search<mytype>(q=>q.SearchType(SearchType.Count)
                    .Query(q2 => q2.Bool(
                        b => b.MustNot(must_not.ToArray())
                        )
                    )
                    .Aggregations(a => a.Terms("termsAggField2", terms => terms.Field("field2").Size(20)
                    .Aggregations(a2 => a2.Sum("sumAggField3", sum => sum.Field("field3"))))));
    

    即为什么我想查看序列化请求并查看我的问题。

    感谢。 问候。

    修改:现在正在使用以下更新。如果我可以序列化它会很棒;)

    List<QueryContainer> must_not = new List<QueryContainer>();
    
                short [] valueCollection = new short[] { 16, 19, 99, 100 };
    
                must_not.Add(Query<mytpe>.Terms(trms => trms.Field("field2").Terms(valueCollection)));
    
    var resultTermsSum = b1.ElasticClient.Search<mytype>(q=>q.SearchType(SearchType.Count)
                    .Query(q2 => q2.Bool(
                        b => b.MustNot(must_not.ToArray())
                        )
                    )
                    .Aggregations(a => a.Terms("termsAggField2", terms => terms.Field("field2").Size(20)
                    .Aggregations(a2 => a2.Sum("sumAggField3", sum => sum.Field("field3"))))));
    

0 个答案:

没有答案