我需要一些帮助来查询我的索引中的字段。此字段都会有这样的数据:Elasticsearch查询
GB10
GB40
GB45
UK09
UK40
如果我有查询:
"Show me the code GB 40"
(注意th e之间的空格GB和40)
我想JSON返回GB40
作为最高结果的结果。任何人都可以帮助我如何才能做到这一点,以及我可能需要做出的任何改变?我还没有设置分析领域。
我需要一些帮助来查询我的索引中的字段。此字段都会有这样的数据:Elasticsearch查询
GB10
GB40
GB45
UK09
UK40
如果我有查询:
"Show me the code GB 40"
(注意th e之间的空格GB和40)
我想JSON返回GB40
作为最高结果的结果。任何人都可以帮助我如何才能做到这一点,以及我可能需要做出的任何改变?我还没有设置分析领域。
好的,如果你有这样的模式的话,那么你可能想要利用弹性的word_delimiter使用word_delimiter标记过滤器来利用split on letter-number transitions: "SD500" → "SD", "500"
。
您可以使用此过滤器在字母词转换中拆分单词,使单词的字母和数字部分分别存储在倒排索引上。 Neverthless这也将保留索引的确切值的副本。
,如果用户输入“EC 450”,你可以建立一个类似的查询,如下面请参考下面
PUT testindex_48
{
"settings": {
"analysis": {
"analyzer": {
"word_delimiter_analyzer": {
"tokenizer": "whitespace",
"filter": [
"lowercase",
"word_delimiter"
],
"ignore_case": true,
"preserve_original": true
}
},
"filter":{
"word_delimiter":{
"type":"word_delimiter",
"generate_word_parts":true,
"preserve_original": true
}
}
}
},
"mappings": {
"table1": {
"properties": {
"title": {
"type": "string",
"analyzer": "word_delimiter_analyzer"
}
}
}
}
}
POST testindex_48/table1
{
"title" : "EC450"
}
POST testindex_48/table1/_search
{
"query": {"bool": {"must": [
{"term": {
"title": {
"value": "450"
}
}}
]}}
}
POST testindex_48/table1/_search
{
"query": {"bool": {"must": [
{"term": {
"title": {
"value": "ec"
}
}}
]}}
}
POST testindex_48/table1/_search
{
"query": {"bool": {"must": [
{"term": {
"title": {
"value": "ec450"
}
}}
]}}
}
现在的映射和查询您的用例。
谢谢这听起来不错,我会测试它。还有一件事让它变得更加令人困惑,在来自mySQL db的同一个字段中,可能有数据只是字母,例如aaabbb,在这里没有简单的方法来确定如何在映射中分割它。如果用户使用空格搜索“aaa bbb”,是否使用某种模糊匹配来获取结果数据?或者有更好的办法可以解决这个问题吗? – Chu
然后我会使用n-gram tokenizer来标记整个字符串,以保持简单而不是潜入模糊匹配的事情.http://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer html的。谢谢 – user3775217
奇妙的建议!感谢您的帮助,我现在已经测试了一切。 – Chu
为什么你试图这样做毫无意义。 – Adi
你能解释一下你的用例吗? –
可以请你出示你的查询和映射,这将使它很容易帮助 – user3775217