【发布时间】:2014-02-12 08:41:24
【问题描述】:
我想从 ElasticSearch 的结果文档中排除一个字段。我浏览了 ElasticSearch.org http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-fields.html 的这个文档,但是当我尝试时这不起作用。我在 SO Is there a way to exclude a field in an Elasticsearch query 上看到了同样的问题,但不幸的是,这也没有给出刚刚从 ElasticSearch 站点粘贴的示例的答案。这是我的代码
{
"query":
{
"multi_match": {
"fields": [
"user",
"email"
],
"query": "John",
"operator": "and",
"type": "phrase_prefix"
}
}
},
"partial_fields" : {
"partial1" : {
"exclude" : "email"
}
},
"from" : 0,
"size" : 10
}
这是上面查询的结果
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "abc",
"_type": "users",
"_id": "4",
"_score": 1,
"_source": {
"user": "John Smith",
"email": "johnsmith_88@yahoo.com",
"pic": "95052dc5bb0bd2575.01687359.jpg"
"utype": "m"
}
},
{
"_index": "abc",
"_type": "users",
"_id": "1",
"_score": 1,
"_source": {
"user": "Johnathan",
"email": "johnathan@ymail.com",
"pic": "428952deea899c6ad3.87100416.jpg"
"utype": "m"
}
}
]
}
}
在上面的查询中,一切正常,但也给出了 Email 字段的结果,我想将此 Email 字段排除在结果文档中。
【问题讨论】:
-
能否提供查询结果?我有一个猜测,但首先必须看到响应。
-
@shyos 我已经用结果更新了我的代码。
-
上述查询是否与您的查询完全相同?如果是,删除
type:phrase_prefix后的1个大括号'}'。 -
哦@shyos 谢谢。我是多么愚蠢。非常感谢解决它。
标签: json lucene elasticsearch