Apply analyzer to multiple documents properties (or on index) at once


#1

I am working on elasticsearch Nest.

I am trying to set analyzer to property of a document but process is always unsuccessful because another document has property with same name .. I am getting below error message:

{Type: illegal_argument_exception Reason: "Mapper for [departmentName] conflicts with existing mapping in other types:
[mapper [departmentName] has different [analyzer]]"}

Here is the code I am using to put mapping:

 ESClientContext.Map<Department>(m => m.Index("company").Type("department")
                 .Properties(p => p
                            .Text(t => t
                                  .Name(n => n.DepartmentName)
                                        .Analyzer("keyword")
                                        .Fielddata(true)
                                     )).UpdateAllTypes(true)); 

Employee also have DepartmentName ..

Please help and guide. Updated as suggested.


(David Pilato) #2

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

There's a live preview panel for exactly this reasons.

Please update your post.

I can't really answer but please be aware that in 6.x you can't have anymore multiple mappings in the same index
So it's better to start thinking of your project a bit differently and have multiple indices for example.

Which will solve your problem. :wink:


#3

I tried "</>" but preview window was not reflecting any change .. so I had to do that .. I am using Opera 51.0 browser.

multiple indices .. is gonna cost us a huge change .. I have approve 25 docs in my index .. I am using 5.5 right now .... so your suggestion is that we should create single index for single doc .. my main issue is analyzer .. I need to index the string as it is .. can you please share any solution for that which can work for me without breaking all docs to many indices? ..

One more point I want to mention .. my index is already created and I want to update the mapping of Department and Employee both .. departmentName analyzer change .. now is there any way to apply mapping change to both at once (that was actually my question, sorry the UI was not so clear to you) .. when I try to do put mapping one by one I am getting exception at first try ...

Hope my case is clear .. please help.


(David Pilato) #5

multiple indices .. is gonna cost us a huge change .. I have approve 25 docs in my index .. I am using 5.5 right now .... so your suggestion is that we should create single index for single doc ..

Yes. Be prepared for 6.x ASAP.

my main issue is analyzer .. I need to index the string as it is .. can you please share any solution for that which can work for me without breaking all docs to many indices? ..

Use a keyword analyzer or a keyword data type in your mapping.

my index is already created and I want to update the mapping of Department and Employee both .. departmentName analyzer change ..

You need to reindex for that. You can not change the settings of an existing field.


#6

Hello dadoonet,

Thanks a lot for your help and time ... recreating index worked for me. :slight_smile: .. hope this will work in 6.x without any issue.


(David Pilato) #7

Do you still have 2 types in your index?


#8

yes .. I have many types/documents in single index.


#9

that means .. one index - one document .. right?


(David Pilato) #10

One index, one type of document.

yes .. I have many types/documents in single index.

So you will be able to upgrade your existing indices to 6.x but you won't be able to upgrade to 7.x.
And you won't be able to create the same data structure from scratch in 6.x.


#11

ok .. so I can't have Employee and Department in same index in 6.x .. but I can upgrade my old index .. but if in future I will have any requirement to reindex .. then I will have to face a huge change .. right? ...

And if now I apply changes keeping 6.x in mind . will that help me with 7.x too?


(David Pilato) #12

Definitely yes.


#13

Hello dadoonet,

I followed your suggestion and changes my mapping to once index one type of document .. actually in my case now I have one document in one index .. now I needed to change analyzer for one on my document's text field but getting this error -

Mapper for [name] conflicts with existing mapping in other types: [mapper [name] has different [analyzer]]

Existing mapping is like this:

"name": {
"type": "text",
"fielddata": true
}

I want to change it to following:

"name": {
"type": "text",
"analyzer": "keyword",
"fielddata": true
},

The index have only one document in it .. but still getting "other types" related issue. Please guide .. how to solve this without removing the index.

Thanks in advance.


(David Pilato) #14

You need to reindex (create a new index and index data again).


(system) closed #15

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.