从ElasticSearch中的结果文档中排除一个字段

时间:2014-01-22 10:33:53

标签: json lucene elasticsearch

我想从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"
            }
        }
    ]
}
}

在上面的查询中,一切正常,但也会在电子邮件字段中显示结果,并且我希望将此电子邮件字段排除在结果文档中。

1 个答案:

答案 0 :(得分:0)

因为它解决了该查询有一个错字。在发送之前,有几种方法可以检查您的查询。

  • 安装elasticsearch-head插件,可帮助您通过简单实用的界面进行查询
  • 或者,在基础级别,您可以使用json解析器网站。例如:http://json.parser.online.fr/