I'm having weird results on some nested objects that I can't understand.
I mean, in mapping the nested objects are all the same, they have an id and a tree id also, both are long and thats it, but profession and category do not return the expected values, but the others do (professionType, professionSubtype and attributeType).
So I got index mapped as:
Mapping:
{
"attribute-tree": {
"mappings": {
"attribute": {
"dynamic": "strict",
"properties": {
"attributeType": {
"properties": {
"id": {"type": "long"},
"tree": {"type": "long"}
}
},
"category": {
"properties": {
"id": {"type": "long"},
"tree": {"type": "long"}
}
},
"family": {"type": "long"},
"id": {"type": "long"},
"name": {
"type": "string",
"index": "not_analyzed"
},
"parentTree": {"type": "long"},
"profession": {
"properties": {
"id": {"type": "long"},
"tree": {"type": "long"}
}
},
"professionSubtype": {
"properties": {
"id": {"type": "long"},
"tree": {"type": "long"}
}
},
"professionType": {
"properties": {
"id": {"type": "long"},
"tree": {"type": "long"}
}
},
"sorter": {
"properties": {
"id": {"type": "long"},
"name": {
"type": "string",
"index": "not_analyzed"
},
"tree": {"type": "long"}
}
},
"suggester": {
"type": "completion",
"index_analyzer": "edgeNGram_analyzer",
"search_analyzer": "whitespace_analyzer",
"payloads": true,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
},
"tree": {"type": "long"},
"type": {"type": "string"}
}
},
"division": {
// same as "attribute"
},
"profession-subtype": {
// same as "attribute"
},
"profession-type": {
// same as "attribute"
},
"profession": {
// same as "attribute"
},
"category": {
// same as "attribute"
}
}
}
}
If any kind of information is missing, please say
Thanks in advance
Example
Filtering by category.id:
POST /attribute-tree/_search
{
"size": 2,
"query": {
"filtered": {
"filter": {
"term": {"category.id": 1}
}
}
}
}
I get:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 31,
"max_score": 1,
"hits": [
{
"_index": "attribute-tree",
"_type": "category",
"_id": "4064",
"_score": 1,
"_source": {
"id": 1,
"tree": 4064,
"name": "Profession",
"type": "C",
"parentTree": 4063,
"profession": {
"id": null,
"tree": null
},
"professionType": {
"id": 1,
"tree": 1
},
"professionSubtype": {
"id": 6,
"tree": 4063
},
"category": {
"id": null,
"tree": null
},
"attributeType": {
"id": null,
"tree": null
},
"family": [
4063,
1
],
"suggester": {
"input": [
"Profession"
],
"output": "Profession"
},
"sorter": {
"name": "Profession",
"id": 1,
"tree": 4064
}
}
},
{
"_index": "attribute-tree",
"_type": "category",
"_id": "4083",
"_score": 1,
"_source": {
"id": 1,
"tree": 4083,
"name": "Profession",
"type": "C",
"parentTree": 4082,
"profession": {
"id": null,
"tree": null
},
"professionType": {
"id": 2,
"tree": 4072
},
"professionSubtype": {
"id": 8,
"tree": 4082
},
"category": {
"id": null,
"tree": null
},
"attributeType": {
"id": null,
"tree": null
},
"family": [
4082,
4072
],
"suggester": {
"input": [
"Profession"
],
"output": "Profession"
},
"sorter": {
"name": "Profession",
"id": 1,
"tree": 4083
}
}
}
]
}
}
Notice that on this example the category.id doesn't have the expected value (this is also valid for when it is 0 instead of null)
However I have nodes with category.id = 1:
POST /attribute-tree/_search
{
"size": 2,
"query": {
"filtered": {
"filter": {
"term": {"tree": 4}
}
}
}
}
Item:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "attribute-tree",
"_type": "profession",
"_id": "4",
"_score": 1,
"_source": {
"id": 1,
"tree": 4,
"name": "A&R Administrator",
"type": "P",
"parentTree": 3,
"profession": {
"id": null,
"tree": null
},
"professionType": {
"id": 1,
"tree": 1
},
"professionSubtype": {
"id": 1,
"tree": 2
},
"category": {
"id": 1,
"tree": 3
},
"attributeType": {
"id": null,
"tree": null
},
"family": [
3,
2,
1
],
"suggester": {
"input": [
"A&R",
"Administrator"
],
"output": "A&R Administrator"
},
"sorter": {
"name": "A&R Administrator",
"id": 1,
"tree": 4
}
}
}
]
}
}
Filtering by professionType.id:
POST /attribute-tree/_search
{
"size": 2,
"query": {
"filtered": {
"filter": {
"term": {"professionSubtype.id": 1}
}
}
}
}
I get:
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3890,
"max_score": 1,
"hits": [
{
"_index": "attribute-tree",
"_type": "category",
"_id": "251",
"_score": 1,
"_source": {
"id": 4,
"tree": 251,
"name": "Medium",
"type": "C",
"parentTree": 2,
"profession": {
"id": null,
"tree": null
},
"professionType": {
"id": 1,
"tree": 1
},
"professionSubtype": {
"id": 1,
"tree": 2
},
"category": {
"id": null,
"tree": null
},
"attributeType": {
"id": null,
"tree": null
},
"family": [
2,
1
],
"suggester": {
"input": [
"Medium"
],
"output": "Medium"
},
"sorter": {
"name": "Medium",
"id": 4,
"tree": 251
}
}
},
{
"_index": "attribute-tree",
"_type": "profession",
"_id": "4",
"_score": 1,
"_source": {
"id": 1,
"tree": 4,
"name": "A&R Administrator",
"type": "P",
"parentTree": 3,
"profession": {
"id": null,
"tree": null
},
"professionType": {
"id": 1,
"tree": 1
},
"professionSubtype": {
"id": 1,
"tree": 2
},
"category": {
"id": 1,
"tree": 3
},
"attributeType": {
"id": null,
"tree": null
},
"family": [
3,
2,
1
],
"suggester": {
"input": [
"A&R",
"Administrator"
],
"output": "A&R Administrator"
},
"sorter": {
"name": "A&R Administrator",
"id": 1,
"tree": 4
}
}
}
]
}
}
Also tested as:
POST /attribute-tree/_search
{
"query":{
"filtered": {
"query": {"match_all":{}},
"filter": {
"nested": {
"path": "category",
"filter": {
"bool": {
"must": [
{"term": {"category.id": 1}}
]
}
}
}
}
}
}
}
But this gives an error
org.elasticsearch.index.query.QueryParsingException: [attribute-tree] [nested] nested object under path [category] is not of nested type