Elasticsearch建议进行条件检查

时间:2016-08-17 11:42:59

标签: elasticsearch

  

以下是我的数据库数据。

fun(const Interface& ob)
  

我需要获得除“私有”之外的其他内容:“true”(即包括没有私有文件的json对象),在我的弹性搜索中。我的弹性搜索查询如下:

{ 
"_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, 
}
  

我需要获取名称以及私有“false”而没有该字段。

1 个答案:

答案 0 :(得分:1)

也许你可以试试这个:

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

我认为您还必须设置默认值" false"对于映射中的私有字段:

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
               }
            }
         }
      }
   }
}'
然而,Haven并没有在弹性搜索中使用上下文建议器。有关详细信息,请参阅Elasticsearch Context Suggester documentation

另请参阅此问题:Elasticsearch context suggester, bool on contexts