0
实际上,我想从我的数据库中的描述为空,在我的结果的mysql查询下面的记录和弹性搜索中的相同结果应该是什么查询?我怎么可以在弹性搜索中使用这个mysql查询
SELECT * FROM products WHERE description!='';
实际上,我想从我的数据库中的描述为空,在我的结果的mysql查询下面的记录和弹性搜索中的相同结果应该是什么查询?我怎么可以在弹性搜索中使用这个mysql查询
SELECT * FROM products WHERE description!='';
弹性搜索查询看起来像这样
POST http://localhost:9200/<index>/<indextype>/_search
{
"query": {
"filtered": {
"filter": {
"term": {
"description": ""
}
}
}
}
}
不过它不工作,检查你的映射应该是这样的。
PUT http://localhost:9200/<index>/<indextype>/_mapping
{
"products": {
"properties": {
"description": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
如果你想要结果与描述!='',然后使用下面的查询。
Missing Filter在Bool Filter的Must-Not部分中。它只会返回字段存在的文档,并且如果将“null_value”属性设置为true,则显式值不为null。
{
"query": {
"filtered": {
"filter": {
"bool":{
"must":{},
"should":{},
"must_not":{
"missing":{
"field":"description",
"existence":true,
"null_value":true
}
}
}
}
}
}
}
感谢vinod,索引必须是“not_analyzed”?如果我想要描述!=''的结果,那么在elasticsearch中应该查询什么? – Rakesh
我已经为您更新了我的答案。请检查。 –
已检查Thans vinod – Rakesh