Solr5.3.1通过copyField设置多个field(字段)同时检索

简介:

 如果业务需要我们对多个field同时进行检索,有没有什么好的办法呢?非常幸运的是Solr为我们提供了copyField对多个field进行索引和检索。然而配置也非常简单。

  修改schame.xml,添加

    <field name="search_item" type="text_ik" indexed="true" stored="false" multiValued="true"/>
    <copyField source="title" dest="search_item"/>
    <copyField source="summary" dest="search_item"/>

  修改后的schema.xml如下:

复制代码
    <!--增加title和summary字段-->
    <field name="title" type="text_ik" stored="true" indexed="true"/> 
    <field name="summary" type="text_ik" stored="true" indexed="true"/>
    <!--按search_item进行检索时,会同时检索title和summary-->
    <field name="search_item" type="text_ik" indexed="true" stored="false" multiValued="true"/>
    <copyField source="title" dest="search_item"/>
    <copyField source="summary" dest="search_item"/>
复制代码

  保存后并重启tomcat并重建索即可。当通过search_item这个field进行检索时,solr会同时去检索title和summary这两个field是否包含相应的关键词,从而达到多个field同时检索的目的。






本文转自秋楓博客园博客,原文链接:http://www.cnblogs.com/rwxwsblog/p/5051498.html,如需转载请自行联系原作者
目录
相关文章
|
23天前
|
PHP
Elasticsearch模糊查询单字段多字段
Elasticsearch模糊查询单字段多字段
16 0
|
2月前
|
Java API iOS开发
Elasticsearch 字段别名 field-alias
Elasticsearch 字段别名 field-alias
27 0
|
10天前
|
索引
RestHighLevelClient查询所有的索引名称
在Elasticsearch中,使用`RestHighLevelClient`查询所有的索引名称可以通过调用`indices().getAlias(GetAliasesRequest, RequestOptions)`方法并检查返回的响应来实现。虽然这个方法通常用于获取别名,但返回的响应中也包含了索引的元数据,因此我们可以利用这个方法来获取所有的索引名称。 不过,更直接的方法是使用`indices().get(GetRequest, RequestOptions)`方法并请求`_all`索引,或者调用`cat().indices(CatIndicesRequest, RequestOptio
|
6月前
|
自然语言处理 索引
09 Lucene索引库查询 - query子类查询
09 Lucene索引库查询 - query子类查询
24 0
|
6月前
|
Java Apache 索引
10 Lucene索引库查询 - queryparser查询
10 Lucene索引库查询 - queryparser查询
22 0
|
8月前
|
关系型数据库 MySQL
PgSQL——通过某字段聚合查询另一个字段的集合
PgSQL——通过某字段聚合查询另一个字段的集合
|
NoSQL MongoDB
MongoDB:查询部分字段,指定返回字段
MongoDB:查询部分字段,指定返回字段
1001 0
|
NoSQL MongoDB
MongoDB(14)- 查询 null 字段或缺少某个字段的文档
MongoDB(14)- 查询 null 字段或缺少某个字段的文档
295 0
|
存储 JSON 自然语言处理
Elasticsearch Mapping之字段类型(field datatypes)
Elasticsearch Mapping之字段类型(field datatypes)
Elasticsearch Mapping之字段类型(field datatypes)