![](/img/trans.png)
[英]How to make a geo distance query only return results that I have not yet "Liked", Elastic Search, Dynamo DB
[英]How can I query an elastic search autocomplete field, and return only certain results?
給定以下映射:
{
"tags": {
"aliases": {},
"mappings": {
"tag": {
"properties": {
"_users": {
"type": "string"
},
"child": {
"type": "string"
},
"level": {
"type": "double"
},
"name": {
"type": "string",
"fields": {
"suggest": {
"type": "completion",
"analyzer": "simple",
"payloads": true,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
}
}
},
"parent": {
"type": "string"
},
"root": {
"type": "boolean"
}
}
}
},
"settings": {
"index": {
"creation_date": "1443688314495",
"number_of_shards": "5",
"number_of_replicas": "1",
"version": {
"created": "1070299"
},
"uuid": "iH0QRRm_QF6pXEZ5sJI4yA"
}
},
"warmers": {}
}
}
同樣, _users
是字符串數組。
如何查詢標記名稱建議,並且僅返回查詢的'id'在_users
數組中的_users
?
這是一個示例標記:
{
"_index": "tags",
"_type": "tag",
"_id": "560b25d8276a6504d808d703",
"_score": 1.0,
"_source": {
"name": "elastic indexed?",
"child": [],
"_users": ["foobar", "someMongoObjectID", "hellothere"],
"_id": "560b25d8276a6504d808d703"
}
}
查看上下文建議器是否可以滿足您的需求。
彼得,謝謝你的主意。 這是基於此的解決方案。
映射:
{
"tags": {
"aliases": {},
"mappings": {
"tag": {
"properties": {
"_users": {
"type": "string"
},
"child": {
"type": "string"
},
"level": {
"type": "double"
},
"name": {
"type": "string",
"fields": {
"suggest": {
"type": "completion",
"analyzer": "simple",
"payloads": true,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50,
"context": {
"_users": {
"type": "category",
"path": "_users",
"default": 'public' // documents with no `_users` or where
//_users.length === 0 should be passed
//'public' as context in the query.
}
}
}
}
},
"parent": {
"type": "string"
},
"root": {
"type": "boolean"
}
}
}
},
"settings": {
"index": {
"creation_date": "1443757145827",
"number_of_shards": "5",
"number_of_replicas": "1",
"version": {
"created": "1070299"
},
"uuid": "Uzb7Rc3sQIafgYD73CSp3g"
}
},
"warmers": {}
}
}
查詢:
/_suggest
{
"tag-suggest": {
"text": "foo",
"completion": {
"field": "name.suggest",
"fuzzy": {},
"context": {
"_users": "someuserID" // or `public` for tags that are not
// associated with at least one user
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.