ElasticSearch - 用连字符搜索名称 [英] ElasticSearch - Searching with hyphens in name

查看:151
本文介绍了ElasticSearch - 用连字符搜索名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个产品目录,我使用Elastica客户端在ElasticSearch中进行索引。我非常新的ElasticSearch BTW。



我的目录中有产品有't-shirt'他们的名字。但是,如果我输入'tshirt',则搜索结果不会出现。



我该怎么做



我已经遵循教程,并为索引实施以下内容:

 'analysis'=> array(
'analyzer'=> array(
'indexAnalyzer'=> array(
'type'=>'custom',
'tokenizer'=> '空白',
'filter'=> array('smallcase','mySnowball')
),
'searchAnalyzer'=>数组(
'type'= "'custom',
'tokenizer'=>'空格',
'filter'=>数组('smallcase','mySnowball')

) ,
'filter'=>数组(
'mySnowball'=>数组(
'type'=>'snowball',
'language'=&英文'




解决方案

您可以尝试使用映射字符过滤器删除连字符:



http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-mapping-charfilter.html



这样会删除连字符:

  {
index:{
analysis:{
char_filter:{
my_mapping:{
type:mapping,
mappings:[ - => ;
}
},
analyzer:{
custom_with_char_filter:{
tokenizer:standard,
char_filter :[my_mapping]
}
}
}
}
}

这是一个钝的力量仪器,因为它会剥除所有连字符,但它应该使T恤和t恤匹配


I have a product catalog which I am indexing in ElasticSearch using the Elastica client. I am very new to ElasticSearch BTW.

There are products in my catalog which have 't-shirt' in their names. But, they won't appear in search results if I type 'tshirt'.

What can I do so that 't-shirt' can also pop-up in results?

I have followed this tutorial and implemented the following for indexes:

'analysis' => array(
    'analyzer' => array(
        'indexAnalyzer' => array(
            'type' => 'custom',
            'tokenizer' => 'whitespace',
            'filter' => array('lowercase', 'mySnowball')
        ),
        'searchAnalyzer' => array(
            'type' => 'custom',
            'tokenizer' => 'whitespace',
            'filter' => array('lowercase', 'mySnowball')
        )
    ),
    'filter' => array(
        'mySnowball' => array(
            'type' => 'snowball',
            'language' => 'English'
        )
    )
)

解决方案

You can try removing the hyphen using a mapping char filter:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-mapping-charfilter.html

something like this would remove the hyphen:

{
    "index" : {
        "analysis" : {
            "char_filter" : {
                "my_mapping" : {
                    "type" : "mapping",
                    "mappings" : ["-=>"]
                }
            },
            "analyzer" : {
                "custom_with_char_filter" : {
                    "tokenizer" : "standard",
                    "char_filter" : ["my_mapping"]
                }
            }
        }
    }
}

it's something of a blunt force instrument as it will strip all hyphens but it should make "t-shirt" and "tshirt" match

这篇关于ElasticSearch - 用连字符搜索名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆