0

My mapping looks like the following:

    "mappings": {
        "nodes": {
            "properties": {
                "createdAt": {
                    "type": "date",
                    "format": "dateOptionalTime"
                },
                "data": {
                    "type": "string"
                },
                "isFile": {
                    "type": "boolean"
                },
                "isPublic": {
                    "type": "boolean"
                },
                "location": {
                    "properties": {
                        "_id": {
                            "type": "string"
                        }
                    }
                },
                "name": {
                    "type": "string"
                },
                "owner": {
                    "properties": {
                        "_id": {
                            "type": "string"
                        },
                        "username": {
                            "type": "string"
                        }
                    }
                },
                "sharedWith": {
                    "type": "object"
                }
            }
        }
    }

When I do the following query:

"filter": {
      "term": {
            "owner.username": "user_69d349"
      }
}

I get proper results, but when I do

"filter": {
    "term": {
        "owner._id": "RvdDC"
    }
}

I get no results.

I'm using the following document:

{
    "_index": "nodess",
    "_type": "nodes",
    "_id": "I7Cac9n",
    "_score": 1.0,
    "_source": {
        "name": "stream",
        "isFile": true,
        "owner": {
            "_id": "RvdDC",
            "username": "user_69349"
        },
        "sharedWith": [],
        "isPublic": false,
        "location": {
            "_id": null
        },
        "data": "baked baked baked hey",
        "createdAt": "2015-03-24T00:53:53.551Z"
    }
}
Deepsy
  • 3,769
  • 7
  • 39
  • 71

1 Answers1

1

I guess this is because you're not using nested type.

Here is a great explanation what's going on when you're not using nested type. Basically your document is being flattened when you're indexing array of objects.

You have to tell ES that you're using nested type.

      "owner": {
            "type": "nested", //<-- declare type here
            "properties": {
                "_id": {
                    "type": "string"
                },
                "username": {
                    "type": "string"
                }
            }
        },
Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64
  • Well, Im not using an array of objects. I'm just using object. See owner field in the example. I tried this already and didn't got much success. – Deepsy Mar 26 '15 at 21:48
  • The thing is that it is working with `owner.username`, but not working with `owner._id` – Deepsy Mar 26 '15 at 21:48
  • Have you check if your document is indexed properly? I mean there's actually `owner._id` field with that value. – Jakub Matczak Mar 26 '15 at 22:04
  • yes, this is the result of http://localhost:9200/nodess/_search, I thought there is something specific with the underscore before name, but could not find anything about it. – Deepsy Mar 26 '15 at 22:06
  • Yeah, that's what I was about to say. It may be matter of `_id` field name which is kind of `reserved` for whole document ID. – Jakub Matczak Mar 26 '15 at 22:08