admin管理员组文章数量:1428993
I have documents stored in MongoDB like so:
const demoArticle = {
created: new Date(),
title: [{
language: 'english',
value: 'This is the english title'
}, {
language: 'dutch',
value: 'Dit is de nederlandse titel'
}]
}
I want to add analyzers to specific languages, which is normally specified like so:
"mappings": {
"article": {
"properties": {
"created": {
"type": "date"
},
"title.value": {
"type": "text",
"analyzer": "english"
}
}
}
}
The problem is however: depending on the language set on the child level, it should have an analyzer set according to that same language.
I've stumbled upon Dynamic Templates in ElasticSearch but I was not quite convinced this is suited for this use-case.
Any suggestions?
I have documents stored in MongoDB like so:
const demoArticle = {
created: new Date(),
title: [{
language: 'english',
value: 'This is the english title'
}, {
language: 'dutch',
value: 'Dit is de nederlandse titel'
}]
}
I want to add analyzers to specific languages, which is normally specified like so:
"mappings": {
"article": {
"properties": {
"created": {
"type": "date"
},
"title.value": {
"type": "text",
"analyzer": "english"
}
}
}
}
The problem is however: depending on the language set on the child level, it should have an analyzer set according to that same language.
I've stumbled upon Dynamic Templates in ElasticSearch but I was not quite convinced this is suited for this use-case.
Any suggestions?
Share Improve this question edited Aug 9, 2018 at 11:52 Bharata 14.2k6 gold badges43 silver badges53 bronze badges asked Jul 25, 2018 at 7:39 randomKekrandomKek 1,1283 gold badges18 silver badges34 bronze badges 5-
1
Depending on the number of languages you need to support, you could have one sub-field per language, i.e.
title_en.value
,title_du.value
, etc each with its own language analyzer. – Val Commented Jul 30, 2018 at 7:46 - 3 To be honest, I don't understand the question. You are offering a second bounty but, in my opinion, you should provide way more details. @Val did offer you an idea above. You care explaining why that would or wouldn't work? Just throwing a bounty out there wouldn't magically giving you the perfect solution. Do answer questions and explain further. As it is now, this is a poorly detailed question imo and the upvotes it got are not deserved. – Andrei Stefan Commented Aug 7, 2018 at 11:18
- 1 I Agree with @AndreiStefan. Going by best practices either use Val's suggestion or create one index per language and then you can search across indices. Is you requirement to have all languages in one field i.e. title? You can hack your way into it by writing custom analyzer to create inverted index based on some separator between the langauges. – Polynomial Proton Commented Aug 7, 2018 at 22:05
- 1 @randomKek any input? – Val Commented Aug 10, 2018 at 3:51
- @randomKek Yeah makes sense, thanks for everybody's input. – randomKek Commented Aug 10, 2018 at 10:10
1 Answer
Reset to default 10 +25If you match MongoDB object language
property to the exact name of the ES language analyzers all you would be needing than as per the remended by Elastic way you would just add:
{
"mappings": {
"article": {
"properties": {
"created": {
"type": "date"
},
"title": {
"type": "text",
"fields": {
"english": {
"type": "text",
"analyzer": "english"
},
"dutch": {
"type": "text",
"analyzer": "dutch"
},
"bulgarian": {
"type": "text",
"analyzer": "bulgarian"
}
}
}
}
}
}
This way you have nice match on the language/analyzer
field between MongoDB and ES.
本文标签: javascriptMultilanguage elastic search mapping setupStack Overflow
版权声明:本文标题:javascript - Multi-language elastic search mapping setup - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745410977a2657468.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论