行动是治愈恐惧的良药,而犹豫、拖延将不断滋养恐惧。

ES在java中的分词

Elasticsearch | 作者 woa666666 | 发布于2018年05月31日 | 阅读数:7461

在elasticearch的组件中配置了ik,在java中使用会不会把查询语句自动分词还是需要调用什么方法
已邀请:

bill

赞同来自:

是否分词取决于列的属性。

定义mapping时,某一列的index属性可以为以下值:analyzed, not_analyzed, no。
默认是analyzed,也就是查询这列时会使用分词。

可以按下面的定义设置not_analyzed。
{
    "fieldname": {
        "type": "string",
        "index": "not_analyzed"
    }
}

The index attribute controls how the string will be indexed. It can contain one of three values:
1. analyzed
  First analyze the string and then index it. In other words, index this field as full text.
2. not_analyzed
  Index this field, so it is searchable, but index the value exactly as specified. Do not analyze it.
3. no
  Don't index this field at all. This field will not be searchable.

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自:

同楼上,注意5.x之后的版本变化。
5.X之后分为text和keyword两种类型。
1、对于text类型,在mapping阶段需要先类似楼上指定Mapping,确立字段类型、分词器选择等;
2、检索的时候,通过match、match_phrase等检索就可以实现全文检索。
建议:先本地DSL验证。验证ok后用java选择对应API就可以了。
 

要回复问题请先登录注册