Reputation: 1753
https://www.elastic.co/blog/index-vs-type
What is a type?
Fields need to be consistent across types. For instance if two fields have the same name in different types of the same index, they need to be of the same field type (string, date, etc.) and have the same configuration.
And "Which one should I use"
Do your documents have similar mappings? If no, use different indices.
But still, in https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child.html it mentions that we need to place parent child documents in same index. But how often does parent-child have similar mappings? And
What i'm trying to investigate is if I should put my 2 different documents in the same index, so I can do parent-child search.
But what I do understand from the index vs type is that documents with different schemas should actually be placed in different indices, but how would then parent-child relationship work?
Upvotes: 0
Views: 2211
Reputation: 1942
The problem is the same field with different typed when you use similar index and different type. To handle this problem, you can use prefix for these fields. For example:
You have a score
field for a type user
and company
. And one of them is integer
and one of them is string
. You should give different name for these score fields.
POST main_index/user/_mapping
{
"properties": {
....
"user_score": {
"type": "integer"
}
}
}
POST main_index/company/_mapping
{
"properties": {
....
"company_score": {
"type": "string"
}
}
}
You need to do same thing all your same named fields.
Upvotes: 1
Reputation: 217564
By "similar mapping", they simply mean that fields with the same name but in two different mapping types must have the same data type.
It is perfectly ok to have different parent and child mapping types, the only constraint is that those two mappings must not contain fields with the same name but different data types.
For instance, if the parent mapping has a field named age
of type int
, the child mapping type cannot have a field named age
of type long
or string
Upvotes: 2