# Problem understanding body queries

**URL:** <https://discuss.elastic.co/t/problem-understanding-body-queries/29839>\
**Category:** Elasticsearch\
**Created:** [September 23, 2015, 12:50pm UTC](https://discuss.elastic.co/t/problem-understanding-body-queries/29839 "2015-09-23T12:50:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcelHallmann](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@MarcelHallmann](https://discuss.elastic.co/u/MarcelHallmann)\
**Post date:** [September 23, 2015, 12:50pm UTC](https://discuss.elastic.co/t/problem-understanding-body-queries/29839/1 "2015-09-23T12:50:54Z")

</div>

Hi,

I hope you can help me to understand the logic behind the body queries.  
Let's assume I have two entries in my Index:

```
{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 24,
    "successful": 24,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 1,
    "hits": [
      {
        "_index": "myindex",
        "_type": "exampleType",
        "_id": "one",
        "_score": 1,
        "_source": {
          "identification": "identification1",
          "certificate": "certificate1",
          "state": "state1"
        }
      },
      {
        "_index": "myindex",
        "_type": "exampleType",
        "_id": "two",
        "_score": 1,
        "_source": {
          "identification": "identification2",
          "certificate": "certificate2",
          "state": "state2"
        }
      }
    ]
  }
}

```

Now I want to query the index to only get the second JSON. I know the identification I'm interested in is "identification2".  
Well, should be a simple query, shouldn't it?

```
{
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "must": {
                        "match": {
                            "_type": "exampleType"
                        }
                    }
                }
            },
            "filter": {
                "term": {
                    "identification": "identification2"
                }
            }
        }
    }
}

```

(Query the index with \_type = exmapletype and then filter the record with the specified identification)  
I think this is as descripted in **Elasticsearch -The definitive guide** chapter "Filtering a query".

But the result list is empty ☹

What am I doing wrong?  
Please help me to understand

---

<div class="post-metadata">

**Author:** ![gmu3](https://avatars.discourse-cdn.com/v4/letter/g/b3f665/32.png) [@gmu3](https://discuss.elastic.co/u/gmu3)\
**Post date:** [September 23, 2015, 6:33pm UTC](https://discuss.elastic.co/t/problem-understanding-body-queries/29839/2 "2015-09-23T18:33:30Z")

</div>

I don't think you want to query by type like that.

You should instead so something like:

```
curl -XGET 'http://localhost:9200/<INDEX_NAME>/exampleType/_search' -d '{
  "query": {
    "filtered": { 
      "filter": {
        "term": { "identification": "identification2" }
      }
    }
  }
}'
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:48pm UTC](https://discuss.elastic.co/t/problem-understanding-body-queries/29839/3 "2017-07-05T23:48:27Z")

</div>


