# How to query against nested attributes where the attribute name has a space in it

**URL:** <https://discuss.elastic.co/t/how-to-query-against-nested-attributes-where-the-attribute-name-has-a-space-in-it/46561>\
**Category:** Elasticsearch\
**Created:** [April 6, 2016, 3:55pm UTC](https://discuss.elastic.co/t/how-to-query-against-nested-attributes-where-the-attribute-name-has-a-space-in-it/46561 "2016-04-06T15:55:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nosocks](https://avatars.discourse-cdn.com/v4/letter/n/cab0a1/32.png) [@nosocks](https://discuss.elastic.co/u/nosocks)\
**Post date:** [April 6, 2016, 3:55pm UTC](https://discuss.elastic.co/t/how-to-query-against-nested-attributes-where-the-attribute-name-has-a-space-in-it/46561/1 "2016-04-06T15:55:51Z")

</div>

When doing a term query on nested documents with spaces, what is the correct syntax? My document looks like this:  
{  
"details": {  
"first name": "jim"  
}  
}

I have a bool query where we are trying to match documents with a first name of `jim`, but it is returning no documents. This is what I've tried:

`{"bool":{"must":[{"term":{"details.first name":"jim"}}]}}`

What is the right way to be querying against nested fields with a space in the field name?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [April 12, 2016, 11:56am UTC](https://discuss.elastic.co/t/how-to-query-against-nested-attributes-where-the-attribute-name-has-a-space-in-it/46561/2 "2016-04-12T11:56:08Z")

</div>

Hi,

there is nothing special about spaces. This works fine with Elasticsearch 2.3:

```auto
PUT /company
{
   "mappings": {
      "employee": {
         "properties": {
            "name": {
               "type": "object",
               "properties": {
                   "first name": {
                       "type": "string",
                       "index": "not_analyzed"
                       
                   },
                   "last name": {
                       "type": "string",
                       "index": "not_analyzed"
                   }
               }
            }
         }
      }
   }
}

POST /company/employee/1
{
   "name": {
      "first name": "Steve",
      "last name": "Jobs"
   }
}

GET /company/employee/_search
{
    "query": {
        "term": {
           "name.first name": {
              "value": "Steve"
           }
        }
    }
}

```

The search returns:

```auto
{
   "took": 30,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.30685282,
      "hits": [
         {
            "_index": "company",
            "_type": "employee",
            "_id": "1",
            "_score": 0.30685282,
            "_source": {
               "name": {
                  "first name": "Steve",
                  "last name": "Jobs"
               }
            }
         }
      ]
   }
}

```

Daniel

---

<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:00pm UTC](https://discuss.elastic.co/t/how-to-query-against-nested-attributes-where-the-attribute-name-has-a-space-in-it/46561/3 "2017-07-05T23:00:11Z")

</div>


