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

1 Answer 1

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"
                }
            }
        },
Sign up to request clarification or add additional context in comments.

5 Comments

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.
The thing is that it is working with owner.username, but not working with owner._id
Have you check if your document is indexed properly? I mean there's actually owner._id field with that value.
yes, this is the result of localhost:9200/nodess/_search, I thought there is something specific with the underscore before name, but could not find anything about it.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.