将 KQL 转换为 C# 对象语法初始化器

Convert KQL to C# Object Syntax Initializer

我有这个查询想要转换为 C# 嵌套查询,它具有用于更新查询的术语过滤器和脚本子句查询在 Kibana Dev Tools 中运行完美但无法转换为嵌套 C# 对象初始化程序语法。

POST acquiringdata/_update_by_query
{
  "script": {
    "inline": "ctx._source.Address = 'FORTRESS STADIUM GROUND FLOOR OPPOSITE_TestasadasD2'",
    "lang": "painless"
  },
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "PaymentTransactionID": {
              "value": "58804121"
            }
          }
        }
      ]
    }
  }
}

到目前为止,该代码的结论是

var filterClause = new List<QueryContainer>();
//  var ScriptClause = new List<ScriptQueryContainer>();
filterClause.Add(new TermQuery
        {
            Field = new Field("PaymentTransactionID"),
            Value = transaction.PaymentTransactionID,
        });

string _templateString = "ctx._source.Address = 'FORTRESS STADIUM GROUND FLOOR OPPOSITE_TestasadasD2'";

// ScriptClause.Add(new ScriptQuery{
//    Name = "named_query",
//    Boost = 1.1,
//    Script = new InlineScript(_templateString)
//    {
//        Params = new Dictionary<string, object> {
//      { "ctx._source.Address", "123" }
//        }
//    }
//});

var SearchRequest = new SearchRequest<NewIndexClass>(NewTestingIndex)
        {
            Size = 1000,
            Query = new BoolQuery
            {
                Must = filterClause,
            }
        };

var searchResponse = _elasticClient.Search<NewIndexClass>(SearchRequest);

if (searchResponse.ApiCall.ResponseBodyInBytes != null)
{
    var requestJson = System.Text.Encoding.UTF8.GetString(searchResponse.ApiCall.RequestBodyInBytes);
    var JsonFormatQuery = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(requestJson), Formatting.Indented);
}

我不用脚本查询也能实现这个输出。

GET _search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "PaymentTransactionID": {
              "value": "58804121"
            }
          }
        }
      ]
    }
  },
  "size": 1000
}

如能将其转换为脚本查询,我们将不胜感激。

我已经做到了

  transaction.Address = "'" + transaction.Address + "'";

                var scriptParams = new Dictionary<string, object>
                    {
                        { nameof(NewIndexClass.Address),transaction.Address}
                    };
                var script = $"ctx._source.Address=" + transaction.Address;
                var searchResponse = _elasticClient.UpdateByQuery<NewIndexClass>(qd =>
                          qd.Index(NewTestingIndex)
                          .Conflicts(Conflicts.Proceed)
                          .Query(rq => rq.Term("PaymentTransactionID", transaction.PaymentTransactionID))
                          .Script(s => s
                              .Source(script)
                               .Params(scriptParams)
                              )
                             );


                if (searchResponse.ApiCall.ResponseBodyInBytes != null)
                {
                    var requestJson = System.Text.Encoding.UTF8.GetString(searchResponse.ApiCall.RequestBodyInBytes);
                    var JsonFormatQuery = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(requestJson), Formatting.Indented);
                }