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?
Hi,
there is nothing special about spaces. This works fine with Elasticsearch 2.3:
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:
{
"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