弹性搜索建议条件检查 [英] Elasticsearch suggest condition check

查看:73
本文介绍了弹性搜索建议条件检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


下面是我的数据库数据。

Here below is my DB data.



{ 
"_id" : ObjectId("572c957244ae959c6517bcb2"), 
"name":"first",
"rating" : 2.0, 
"private" : "true"
}
{ 
 "_id" : ObjectId("572c957244ss959c6517bcb2"), 
"name":"first",
"rating" : 2.0, 
"private" : "false"
}
{ 
"_id" : ObjectId("572c9dfef44ae959c6517bcb2"), 
"name":"first",
"rating" : 2.0, 
"private" : "false"
}
{ 
"_id" : ObjectId("572c9dfef44ae959c6517bcb2"), 
"name":"first",
"rating" : 2.0, 
}




我需要得到其他private:true(即包括没有私有文件的json对象)在我的弹性搜索。我的弹性搜索查询获取如下

I need to get other than "private" :"true" (i.e including json object without private filed) , in my elasticsearch .My elasticsearch query to fetch is as follow



curl -XGET 'localhost:9200/tellofy/_suggest?pretty' -d '
{"brand-suggest":  {"completion":"field":"nameSuggest","size":"5"},   "text":"first"}}'




什么我需要得到这个名字以及私人的false,没有这个字段。

what I need to get the name along with private "false" and without that field.


推荐答案

也许你可以试试这个:

curl -XGET 'localhost:9200/tellofy/_suggest?pretty' -d '
{
   "brand-suggest": {
      "completion": {
         "field": "nameSuggest",
         "size": "5",
         "context": {
            "private": "false"
         }
      },
      "text": "first"
   }
}'

我想你还必须为映射中的私有字段设置默认值false :

I think you will also have to set a default value "false" for the private-field in the mapping:

curl -X PUT "http://localhost:9200/tellofy/test/_mapping" -d'
{
   "test": {
      "properties": {
         "name": {
            "type": "string"
         },
         "rating": {
            "type": "float"
         },
         "private": {
            "type": "boolean"
         },
         "nameSuggest": {
            "type": "completion",
            "context": {
               "private": {
                  "type": "category",
                  "path": "private",
                  "default": false
               }
            }
         }
      }
   }
}'

没有在弹性搜索中自己使用上下文提示。请参阅弹性搜索上下文Suggester文档更多信息。

Haven't used the context suggesters myself in elasticsearch though. See the Elasticsearch Context Suggester documentation for more info.

另请参阅此问题:弹性搜索上下文建议,在上下文中显示

这篇关于弹性搜索建议条件检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆