Will updating "_mappings" reflect any changes in Indexed data in Elastic search - elasticsearch

I didn't found any change in my search result even after updating some fields in my index[_mapping]. so i want to know that "Will updating "_mappings" reflect re-indexing data in Elastic search" [or] "only data inserted after updation will effect with those index parameters[settings n mappings]"
EX:
Initially i've created my index fields as following
"fname":{
"type":"string",
"boost":5
}
"lname":{
"type":"string",
"boost":1
}
then i inserted some data. its working fine.
After updating my index mapping as following,
"fname":{
"type":"string",
"boost":1
}
"lname":{
"type":"string",
"boost":5
}
Still after updating boost values in index, also i'm getting same result.... why?
1: after each and every updation of index [settings n mapping], will elastic-search re-index the data again?
2: do we have different indexed data in same item-type?
Plz clarify this.

While you can add fields to the mappings of an index, any other change to already existing fields will either only operate on new documents or fail.
As mentioned in the comments to the question, there is an interesting article about zero-downtime index switching and there is a whole section about index management in the definitive guide.

Related

How to find what index a field belongs to in elasticsearch?

I am new to elasticsearch. I have to write a query using a given field but I don't know how to find the appropriate index. How would I find this information?
Edit:
Here's an easier/better way using mapping API
GET _mapping/field/<fieldname>
One of the ways you can find is to get records where the field exist
Replace the <fieldName> with your fields name. /_search will search across all indices and return any document that matches or has the field. Set _source to false, since you dont care about document contents but only index name.
GET /_search
{
"_source": false,
"query": {
"exists": {
"field": "<fieldName>"
}
}
}
Another, more visual way to do that is through the kibana Index Management UI (assuming you have privileges to access the site).
There you can click on the indices and open the mappings tab to get all fields of the particular index. Then just search for the desired field.
Summary:
#Polynomial Proton's answer is the way of choice in 90% of the time. I just wanted to show you another way to solve your issue. It will require more manual steps than #Polynomial Proton's answer. Also, if you have a large amount of indices this way is not appropriate.

Overwrite/Update Existing Elasticsearch Index Mapping (geo_point) using Kibana

I am trying to update the mapping for a geo_point field in my elasticsearch index but am running into issues. I am using the dev tool console in Kibana.
The data for the geo_point is in a double array format . I am using spark with the elasticsearch-hadoop-5.3.1.jar and the data is coming into elasticsearch/kibana but remains as a number format while I need to convert it to a geo_point.
It seems that I am unable to update the index mapping once it is defined. I've tried using the method below:
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"my_location": {
"type": "geo_point"
}
}
}
}
}
-but this results in an "index already exists exception" error.
Thanks for any suggestions.
The command you used just try to create new index with mappings mentioned. For more information read the foot notes in first example here .
As per Elasticsearch documentation, updating mappings of an existing field is not possible.
Updating Field Mappings
In general, the mapping for existing fields cannot be updated. There
are some exceptions to this rule. For instance:
new properties can be added to Object datatype fields.
new multi-fields can be added to existing fields.
the ignore_above parameter can be updated.
As geo_point doesn't fall into any case mentioned above, you cannot modify mappings of that field.
You might need to reindex the data.

Adding new fields to mappings requires re-indexing data in elastic search

I'm using elastic search 1.7.2, As i want to add new fields to existing mappings, do i need to re index entire data?
Ex:
Mappings:
{
"properties":{
"a":{"type":string},
"b":{"type":string}
}
}
If i want to add field "c", do we need to re-index entire data?. please help me, thanks in advance.

Elasticsearch: multi indices one type OR one index multi types

As The Definitive Guide -> Indexing Employee Documents said
Relational DB ⇒ Databases ⇒ Tables ⇒ Rows ⇒ Columns
Elasticsearch ⇒ Indices ⇒ Types ⇒ Documents ⇒ Fields
And The Definitive Guide -> Index Aliases and Zero Downtime said
Be prepared: use aliases instead of indices in your application. Then you will be able to reindex whenever you need to. Aliases are cheap and should be used liberally.
The question is, if Indices just like Databases, then if I want to rebuild one Type(Table) I have to reindex the whole Database, is that reasonable ? (this is one index multi types).
Or I have to create many indices for a project and every index has just one type, that sounds like a project has dozens databases!
I think I understand your confusion. Say You have one index named my_index and three types type1, type2 and type3. You create an alias alias1 for this index.
Now you want to change mapping of type1, so you need to reindex every document of type1 but you want to do this with zero downtime so you create a new index index2 and reindex documents of type1 and now if you want alias1 to refer to new index, problem will arise and as you said you will have to reindex all other types too only if you want zero downtime. If you are ok with downtime then obviously you can delete all the documents and reindex them.
To solve the above issue you should create multiple aliases for the same index beforehand as described here,look for the section named Using aliases for greater flexibility . You create 3 aliases for current index like this
curl - XPOST localhost:9200/_aliases - d ' {
"actions": [{
"add": {
"alias": "type1_alias",
"index": "index1"
}
}, {
"add": {
"alias": "type2_alias",
"index": "index1"
}
},
{
"add": {
"alias": "type3_alias",
"index": "index1"
}
}]
}
'
Now you index type1 docs to type1_alias and so on. Now whenever you want to rebuild any specific type you can create new index and assign specific type alias to that new index. You also have to remove that particular type documents from old index(index1 in this case)
This would have been lot easier if alias had support on type level, somebody opened an issue about that but it was closed due to complexity I guess.
Hope this helps!!
You can work with one index and multiple types.
You can re-index documents of a given type within an index without affecting other documents in the same index but belonging to other types. As a matter of fact each document in an index can be re-indexed without having to re-index other documents.

Enabling Elasticsearch _size field

I have an index with over 9,000,000 docs.
I have defined my own mapping and everything went fine.
The only problem is that I forgot to enable the _size field and now I need it to localize document with a large size.
From the documentation I found that it's just fine to use the PUT mapping API with these parameters:
{
"my_index": {
"_size": {
"enabled": true
}
}
}
Does the new mapping will be merged with the one already set?
Does the size field will be enabled for already stored documents?
I am a little worried making changes to mapping beacuse the last time that I have updated the settings with a new analyzer the service was having problem due to shard relocation and everything got stuck.
The mappings will be merged OK and the _size field will be enabled for all your documents of type my_index.
Note that if you want to store the _size (in addition to just index its value), you also need to add "store": "yes" in your _size mapping.
Unfortunately, you'll need to re-index your data in order for the _size field to be properly indexed.

Resources