我正在尝试使用DeleteByQuery(..)方法从ElasticSearch中删除特定文档,但它不起作用。我得到的回复显示200状态。
如果我搜索相同的查询,我可以得到结果。
以下是我的查询 -
FilterContainer[] container = new FilterContainer[2];
FilterContainer TypeFilter = new TermFilter
{
Field = "TYPE",
Value = TableName
};
FilterContainer BRConnectionIDFilter = new TermFilter
{
Field = "BRCONNECTIONID",
Value = BRConnectionID
};
container[0] = TypeFilter;
container[1] = BRConnectionIDFilter;
IDeleteResponse response = objElasticNestClient.DeleteByQuery<dynamic>(s => s.Index(ExtractionContext.ElasticSearchIndex).Query(b => b.Filtered(q => q.Query(a => a.MatchAll()).Filter(f => f.Bool(m => m.Must(container))))));
if (!response.IsValid && response.ConnectionStatus.HttpStatusCode == 200)
{
throw new Exception("Delete failed for object " + TableName + ". Error: " + response.ServerError);
}
我已将INDEX用作所有字段的NOT_ANALYZED。
有人可以指导我吗?
答案 0 :(得分:0)
在替换下面的查询后它起作用了 -
IDeleteResponse response = objElasticNestClient.DeleteByQuery<dynamic>(s => s.Index(ExtractionContext.ElasticSearchIndex).Type(TableName).Query(b => b.Filtered(q => q.Query(a => a.MatchAll()).Filter(f => f.Term("BRCONNECTIONID", BRConnectionID)))));
if (!response.IsValid && response.ConnectionStatus.HttpStatusCode == 200)
{
throw new Exception("Delete failed for object " + TableName + ". Error: " + response.ServerError);
}