我使用concatenating double quoted
动态添加到列表中的数字,并按如下方式输入代码
ArrayList arrRespId = new ArrayList();
for (int i = 0; i < hitsCountRespId; i++)
{
arrRespId.Add("\"" + jsonRespId["aggregations"]["my_fields"]["buckets"][i]["key"].ToString() + "\"");
} //Adding all numbers in the list with double quoted
var strDouble = string.Join(",", arrRespId.ToArray()); //"5","6","7"
嘿伙计我有lambda expression
的代码,可以从Elasticsearch
var SearchAggregate = client.Search<string>(sd => sd
.Index("Index")
.Type("Table")
.Size(0)
.Query(q => q
.Bool(b => b
.Must(
m => m.Terms("QID", new[] { strDouble.tostring() }),
m => m.Terms("ProjectID", new[] { "50" }),
m => m.Terms("RespID", new[] { abc.ToString() })
//m => m.Terms("RespID", new[] { "1","2" })
)))));
但问题是当我将这个双引号字符串放在lambda表达式中时它采用"\"5\",\"6\",\"7\",....
并且我的代码没有返回任何内容
我会感谢您的帮助!谢谢
答案 0 :(得分:1)
我看到你的代码和图像输出错误地理解了term
在lambda表达式中的期望,它不期望双引号或字符
term
期望包含所需数字的字符串数组,代码应如下所示
string[] arrRespId= new arrRespId[50]; //in your scenario you can put `hitsCountRespId` as array size
for (int i = 0; i < hitsCountRespId; i++)
{
arrRespId[i]= jsonRespId["aggregations"]["my_fields"]["buckets"][i]["key"].ToString();
}
然后将string array
放在lambda表达式中,如下所示
var SearchAggregate = client.Search<string>(sd => sd
.Index("Index")
.Type("Table")
.Size(0)
.Query(q => q
.Bool(b => b
.Must(
m => m.Terms("QID", new[] { strDouble.tostring() }),
m => m.Terms("ProjectID", new[] { "50" }),
m => m.Terms("RespID", arrRespId)
)))));
我希望它对你有用。