【发布时间】:2017-02-26 03:19:35
【问题描述】:
我正在尝试对搜索查询使用过滤器。搜索请求在没有过滤器的情况下正常工作。但是使用过滤器我得到 400 错误作为响应。 这是类型映射:
var mapp = new
{
mappings = new
{
posts = new
{
properties = new
{
FullText = new
{
type = "string",
analyzer = "russian"
},
Title = new
{
type = "string",
analyzer = "russian"
},
PostPubDate = new
{
type = "date"
},
Link = new
{
type = "string",
index = "not_analyzed"
},
RubricsIds = new
{
type = "integer"
},
ObjectsIds = new
{
type = "integer"
},
SourceId = new
{
type = "integer"
}
}
}
}
};
这是一个使用过滤查询索引的请求:
string url = "http://localhost:9200/neg_collector/posts/_search";
var request = (HttpWebRequest)HttpWebRequest.Create(url);
var o = new
{
size = 20,
query = new
{
filtered = new
{
query = new
{
query_string = new
{
fields = new[] { "Title" },
query = search_query
}
},
filter = new
{
@bool = new
{
should = new
{
term = new
{
SourceId = sIds
}
}
}
}
}
}
};
request.Method = "POST";
var jsonObj = JsonConvert.SerializeObject(o);
var data = Encoding.UTF8.GetBytes(jsonObj);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
我想使用整数数组来过滤具有特定 SourceId-s 的结果。但我收到错误 400。 我究竟做错了什么?谢谢
【问题讨论】:
-
你的 ES 版本是什么,你的原始反应是什么?请分享。
-
另一方面,您应该使用 application/json 内容类型。
-
@hkulekci 是的,问题出在 ES 的版本上(我用 ES2 尝试了这段代码,它有效。现在它不适用于 ES 5)
标签: c# elasticsearch