我想创建动态查询(列表中的每个单词都创建新的QueryString并放入QueryContainer [])。但它不起作用。我无法创建QueryStringQuery并得到此错误:“非泛型类型字段不能与类型一起使用”。通过这个网站它应该工作https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/query-string-usage.html
我的代码是:
public IEnumerable<ElasticSearchDocument> Search(int tabId, string textToSearch)
{
string text = MakeTextToSearch(textToSearch);
List<string> temp = MakeStrings(text);
QueryContainer[] querys = null;
for (int i = 0; i < temp.Count; i++)
{
querys|= new QueryStringQuery()
{
Fields = Field<ElasticSearchDocument>(x => x.FullPlainText),
DefaultField = "FullPlainText",
Query = temp[i],
DefaultOperator = Operator.Or
};
}
var searchResults = client.Search<ElasticSearchDocument>(s => s
.Query(q => q.Bool(b => b
.Must(querys)
)
)
);
return searchResults.Documents;
}
现在全部工作。我改变了:
querys |= Query<ElasticSearchDocument>.QueryString(x => x.Fields(f => f.Field(c => c.FullPlainText)).Query(temp[i]));