1

I want to exclude a field from resulted Documents in ElasticSearch. I went through this document of ElasticSearch.org http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-fields.html but this doesn't work when I try. I have seen the same question on SO Is there a way to exclude a field in an Elasticsearch query but unfortunately that also doesn't give the answer just pasted example from ElasticSearch site. Here is my code

{
        "query":
        {
             "multi_match": {
                  "fields": [
                  "user",
                  "email"
                  ],
                  "query": "John",
                  "operator": "and",
                  "type": "phrase_prefix"
              }
        }
    },
        "partial_fields" : {
        "partial1" : {
            "exclude" : "email"
        }
    },
        "from" : 0,
        "size" : 10
}

Here is the result of above query

{
"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"
            }
        }
    ]
}
}

in the above query everything works fine but that gives result with Email field as well and I want to exclude this Email field from being in resulted documents.

Community
  • 1
  • 1

1 Answers1

0

As it is solved with that query has a typo. There are several ways to check your query before sending.

  • Either install elasticsearch-head plugin, which helps you to query through simple and useful interface
  • or, on basic level, you can use json parser websites. Such as: http://json.parser.online.fr/
shyos
  • 1,390
  • 1
  • 16
  • 29
  • Thanks for extra info and providing support. @shyos, I have posted another question please check if you can answer that as well. http://stackoverflow.com/questions/21285524/get-only-result-documents-in-elasticsearch-excluding-other-meta-data-with-php-li –  Jan 22 '14 at 14:25