通过java代码实现ES中的常用搜索

这篇具有很好参考价值的文章主要介绍了通过java代码实现ES中的常用搜索。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

测试环境准备

在指定索引下搜索全部(可以指定字段)

通过ids进行搜索

对搜索结果进行分页

match分词搜索

不分词模糊搜索:wildcardQuery与matchPhraseQuery

term 搜索(精确匹配)

multi_match搜索

bool搜索 多条件匹配

filter过滤搜索

sort排序搜索

后续待补充:queryStringQuery,minimumShouldMatch,对检索结果中的关键词进行高亮


测试环境准备

测试环境:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>2.0.6.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <version>2.0.6.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
    <version>7.3.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>7.3.0</version>
</dependency>

2配置 application.yml

spring:
  application:
    name: service-search
eslearn:
  elasticsearch:
    hostlist: 127.0.0.1:9200 #多个结点中间用逗号分隔

 3主类代码

@SpringBootApplication
public class SearchApplication {
    public static void main(String[] args) {
        SpringApplication.run(SearchApplication.class,args);
    }
}

配置类:

package com.learn.es.cofig;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LJM
 * @create 2022/12/10
 */
@Configuration
public class ElasticSearchConfig {
    
    @Value("${eslearn.elasticsearch.hostlist}")
    private String hostList;
    
    @Bean(destroyMethod = "close") //表示连接使用完成后需要关闭
    public RestHighLevelClient restHighLevelClient(){
        String[] split = hostList.split(",");
        //这种写法是考虑到可能会配置多个es节点
        HttpHost[] httpHosts = new HttpHost[split.length];
        for (int i = 0; i < split.length; i++) {
            String item = split[i];
            httpHosts[i] = new HttpHost(item.split(":")[0],Integer.parseInt(item.split(":")[1]),"http");
        }

        return new RestHighLevelClient(RestClient.builder(httpHosts));
    }
    
}

测试项目结构:

java es搜索引擎,elasticsearch,java,elasticsearch,spring boot

 在kibana中把数据插入es中:

delete book   //先删除索引

PUT /book    //往索引中插入数据进行测试,后面在api实现搜索的小节,可以使用从数据库中读取数据 然后把数据插入es库指定的索引

PUT /book/_doc/1
{
"name": "Bootstrap开发",
"description": "Bootstrap是由Twitter推出的一个前台页面开发css框架,是一个非常流行的开发框架,此框架集成了多种页面效果。此开发框架包含了大量的CSS、JS程序代码,可以帮助开发者(尤其是不擅长css页面开发的程序人员)轻松的实现一个css,不受浏览器限制的精美界面css效果。",
"studymodel": "201002",
"price":38.6,
"timestamp":"2019-08-25 19:11:35",
"pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg",
"tags": [ "bootstrap", "dev"]
}


PUT /book/_doc/2
{
"name": "java编程思想",
"description": "java语言是世界第一编程语言,在软件开发领域使用人数最多。",
"studymodel": "201001",
"price":68.6,
"timestamp":"2019-08-25 19:11:35",
"pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg",
"tags": [ "java", "dev"]
}




PUT /book/_doc/3
{
"name": "spring开发基础",
"description": "spring 在java领域非常流行,java程序员都在用。",
"studymodel": "201001",
"price":88.6,
"timestamp":"2019-08-24 19:11:35",
"pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg",
"tags": [ "spring", "java"]
}

测试类代码结构: 

/**
 * @author LJM
 * @create 2022/12/13
 * 测试使用java代码实现es的各种搜索
 */
@SpringBootTest(classes = SearchApplication.class)
@RunWith(SpringRunner.class)
public class TestSearch {
    @Autowired
    RestHighLevelClient client;

// 后面的测试方法会全部写在这个类中 .....

}

在指定索引下搜索全部(可以指定字段)

在kibana中 GET /book/_search 先获取一下本地es库中的book索引下有多少数据。

/**
     *     搜索全部
     *       GET book/_search
     *       {
     *         "query": {
     *          "match_all": {}
     *          }
     *       }
     * @throws IOException
     */
    @Test
    public void testSearchAll() throws IOException {

        //1构建搜索请求  实际生产环境中这个索引名称的获取:①把这个索引名称写在枚举类中,然后从枚举类中获取②从配置文件中获取
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.matchAllQuery());

        //获取某些字段
        searchSourceBuilder.fetchSource(new String[]{"name"}, new String[]{});

        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("score:" + score);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

通过ids进行搜索

 /**
     * 通过ids进行搜索  有的就查询出来,没有的也不会报错
     *     GET /book/_search
     *     {
     *         "query": {
     *            "ids" : {
     *              "values" : ["1", "2", "6"]
     *              }
     *         }
     *     }
     * @throws IOException
     */
    @Test
    public void testSearchIds() throws IOException {

        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.idsQuery().addIds("1","2","6"));

        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

对搜索结果进行分页

    /**
     *     对搜索结果进行分页
     *         GET book/_search
     *         {
     *             "query": {
     *               "match_all": {}
     *            },
     *             "from": 0,
     *             "size": 2
     *         }
     */
    @Test
    public void testSearchPage() throws IOException {
        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.matchAllQuery());

        //搜索第几页的数据
        int page=1;
        //每页展示几个数据
        //int size=2;  //因为本地es一共就插入了三条数据进行测试,所以可以把大小分别设置为2和3看一下输出效果
        int size=3;
        //下标计算
        int from = (page-1) / size;

        searchSourceBuilder.from(from);
        searchSourceBuilder.size(size);

        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

match分词搜索

 /**
     * match搜索  这个是会进行分词搜索的
     *     GET /book/_search
     *     {
     *         "query": {
     *            "match": {
     *             "description": "java程序员"
     *         }
     *       }
     *     }
     * @throws IOException
     */
    @Test
    public void testSearchMatch() throws IOException {
        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(QueryBuilders.matchQuery("description", "java程序员"));


        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

不分词模糊搜索:wildcardQuery与matchPhraseQuery

    /**
     * 不分词模糊搜索   like '%检索词%'
     * @throws IOException
     */
    @Test
    public void testSearchLike() throws IOException {
        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        //使用matchPhraseQuery 需要对检索的关键词的前后加 * 否则不是完全的模糊匹配  可以对检索的结果中的检索关键词进行高亮
        searchSourceBuilder.query(QueryBuilders.matchPhraseQuery("description", "*"+"程序员"+"*"));

        //还可以使用wildcardQuery 但是这种就会导致检索的结果不能高亮(这个不太确定,但是我自己试的时候,这样确实是不能对检索结果中的检索词进行高亮)
        //需要在检索的字段名后拼接 ".keyword"  并且也需要对检索词前后添加 *
//        searchSourceBuilder.query(QueryBuilders.wildcardQuery("description"+".keyword","*"+"程序员"+"*"));



        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

term 搜索(精确匹配)

 /**
     * term 搜索  如果字段为keyword那么【存储】和【搜索】都不分词。 搜索的时候相当于在使用 = 符号进行搜索
     *        GET / book / _search
     *         {
     *             "query":{
     *                 "term":{
     *                     "description":"java程序员"
     *                 }
     *             }
     *         }
     * @throws IOException
     */
    @Test
    public void testSearchTerm() throws IOException {

        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        //如果字段的映射是text但是也想要精确匹配,可以这样操作:QueryBuilders.termQuery("description" + ".keyword","java程序员")
        searchSourceBuilder.query(QueryBuilders.termQuery("description", "java语言"));

        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

multi_match搜索

    /**
     * multi_match搜索
     *     GET /book/_search
     *     {
     *         "query": {
     *           "multi_match": {
     *             "query": "java程序员",
     *             "fields": ["name", "description"]
     *         }
     *       }
     *     }
     * @throws IOException
     */
    @Test
    public void testSearchMultiMatch() throws IOException {

        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        //第二个参数才是 字段  第一个参数是匹配的内容
        searchSourceBuilder.query(QueryBuilders.multiMatchQuery("java程序员","name","description"));

        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

bool搜索 多条件匹配

    /**
     * bool搜索 多条件匹配  and or !=
     *         GET / book / _search
     *         {
     *          "query":{
     *             "bool":{
     *                 "must": [
     *                 {
     *                     "multi_match":{
     *                     "query":"java程序员",
     *                             "fields": ["name", "description"]
     *                     }
     *                 }
     *                 ],
     *                 "should": [
     *                     {
     *                         "match":{
     *                         "studymodel":"201001"
     *                     }
     *                 }
     *                 ]
     *             }
     *         }
     *       }
     * @throws IOException
     */
    @Test
    public void testSearchBool() throws IOException {

        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

        //构建multiMatch请求 第一个参数是检索内容 第二个参数是检索的字段
        MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery("java程序员", "name", "description");
        //构建match请求
        MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("name", "测试没有的字段");

        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        boolQueryBuilder.must(multiMatchQueryBuilder);
        boolQueryBuilder.should(matchQueryBuilder);
        //        boolQueryBuilder.must(matchQueryBuilder); //把should改成must就相当于用 and进行了再一次的过滤 就会查询不到数据

        searchSourceBuilder.query(boolQueryBuilder);
        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

}

filter过滤搜索

过滤搜索和范围搜索的区别:

filter,仅仅只是按照搜索条件过滤出需要的数据而已,不计算任何相关度分数,对相关度没有任何影响。

query,会去计算每个document相对于搜索条件的相关度,并按照相关度进行排序。文章来源地址https://www.toymoban.com/news/detail-801775.html

    /**
     * filter过滤搜索
     *     GET /book/_search
     *     {
     *         "query": {
     *           "bool": {
     *             "must": [
     *             {
     *                 "multi_match": {
     *                 "query": "java程序员",
     *                         "fields": ["name","description"]
     *                                      }
     *             }
     *       ],
     *             "should": [
     *             {
     *                 "match": {
     *                 "studymodel": "201001"
     *             }
     *             }
     *           ],
     *             "filter": {
     *                 "range": {
     *                     "price": {
     *                         "gte": 50,
     *                          "lte": 90
     *                     }
     *                 }
     *
     *             }
     *         }
     *     }
     *  }
     * @throws IOException
     */
    @Test
    public void testSearchFilter() throws IOException {

        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

        //构建multiMatch请求
        MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery("java程序员", "name", "description");
        //构建match请求
        MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("studymodel", "201001");

        BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
        boolQueryBuilder.must(multiMatchQueryBuilder);
        boolQueryBuilder.should(matchQueryBuilder);

        boolQueryBuilder.filter(QueryBuilders.rangeQuery("price").gte(50).lte(90));

        searchSourceBuilder.query(boolQueryBuilder);

        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");

        }
    }

sort排序搜索

    /**
     * sort排序搜索
     *     GET /book/_search
     *     {
     *         "query": {
     *         "bool": {
     *             "must": [
     *             {
     *                 "multi_match": {
     *                 "query": "java程序员",
     *                         "fields": ["name","description"]
     *             }
     *             }
     *       ],
     *             "should": [
     *             {
     *                 "match": {
     *                 "studymodel": "201001"
     *             }
     *             }
     *       ],
     *             "filter": {
     *                 "range": {
     *                     "price": {
     *                         "gte": 50,
     *                                 "lte": 90
     *                     }
     *                 }
     *
     *             }
     *         }
     *     },
     *         "sort": [
     *         {
     *             "price": {
     *             "order": "asc"
     *         }
     *         }
     *   ]
     *     }
     * @throws IOException
     */
    @Test
    public void testSearchSort() throws IOException {

        //1构建搜索请求
        SearchRequest searchRequest = new SearchRequest("book");

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

        //构建multiMatch请求
        MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery("java程序员", "name", "description");
        //构建match请求
        MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("studymodel", "201001");

        BoolQueryBuilder boolQueryBuilder=QueryBuilders.boolQuery();
        boolQueryBuilder.must(multiMatchQueryBuilder);
        boolQueryBuilder.should(matchQueryBuilder);

        boolQueryBuilder.filter(QueryBuilders.rangeQuery("price").gte(50).lte(90));

        searchSourceBuilder.query(boolQueryBuilder);

        //按照价格升序
        searchSourceBuilder.sort("price", SortOrder.ASC);


        searchRequest.source(searchSourceBuilder);

        //2执行搜索
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

        //3获取结果
        SearchHits hits = searchResponse.getHits();

        //数据数据
        SearchHit[] searchHits = hits.getHits();
        System.out.println("--------------------------");
        for (SearchHit hit : searchHits) {
            String id = hit.getId();
            float score = hit.getScore();
            //这个source里面就是我们存储的数据
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            String name = (String) sourceAsMap.get("name");
            String description = (String) sourceAsMap.get("description");
            Double price = (Double) sourceAsMap.get("price");
            System.out.println("id:" + id);
            System.out.println("name:" + name);
            System.out.println("description:" + description);
            System.out.println("price:" + price);
            System.out.println("==========================");
        }
    }

后续待补充:queryStringQuery,minimumShouldMatch,对检索结果中的关键词进行高亮

到了这里,关于通过java代码实现ES中的常用搜索的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【分布式搜索引擎es】

    elasticsearch最擅长的是 搜索 和 数据分析 。 查询文档 常见的查询类型包括: 查询所有 :查询出所有数据,一般测试用。例如:match_all 全文检索(full text)查询 :利用分词器对用户输入内容分词,然后去倒排索引库中匹配。例如: match_query multi_match_query 精确查询 :根据精确

    2024年02月10日
    浏览(48)
  • 分布式搜索引擎ES

    elasticsearch的作用 elasticsearch是一款非常强大的开源搜索引擎,具备非常多强大功能,可以帮助我们从海量数据中快速找到需要的内容 例如: 在GitHub搜索代码 在电商网站搜索商品 在百度搜索答案 ELK技术栈 elasticsearch结合kibana、Logstash、Beats,也就是elastic stack(ELK)。被广泛应

    2024年02月04日
    浏览(41)
  • 详解最热门搜索引擎——ES

    ​ 互联网发展早期的时候,对于一般的公司储存的数据量不是那么的大,所以很多公司更倾向于使用数据库去存储和查询数据,如:现在去MySQL中查询数据,大概的查询方式就是:select * from table where filed like “%XXX%”或者其他方式,但是,如果我们在查询的时候没有用到或命

    2023年04月10日
    浏览(44)
  • Elasticsearch (ES) 搜索引擎: 搜索功能:搜索分页、搜索匹配、全文搜索、搜索建议、字段排序

    原文链接:https://xiets.blog.csdn.net/article/details/132348920 版权声明:原创文章禁止转载 专栏目录:Elasticsearch 专栏(总目录) ES 搜索 API 官网文档:Search APIs 先创建一个索引,并写入一些文档用于搜索示例: 写入一些文档示例: 官网API:The _source option 搜索结果中的文档数据封装

    2024年02月08日
    浏览(53)
  • RediSearch比Es搜索还快的搜索引擎

    RediSearch是一个Redis模块,为Redis提供查询、二次索引和全文搜索。要使用RediSearch,首先要在Redis数据上声明索引。然后可以使用重新搜索查询语言来查询该数据。RedSearch使用压缩的反向索引进行快速索引,占用内存少。RedSearch索引通过提供精确的短语匹配、模糊搜索和数字过

    2024年04月11日
    浏览(37)
  • 搜索引擎ES-RestHighLevelClient

    前言:本篇文章,主要讲述如何引入RestHighLevelClient,以及对其API的调用,属于入门级别的接口实用。适用于由于工作需要及时了解的童靴们以及初学者。想要了解ES底层更多内容的童鞋们,本篇文章并不适合 ! 前言:对比mysql,了解ES 首先通过图片对比我们了解的关系型数据

    2024年02月08日
    浏览(40)
  • 分布式搜索引擎es-3

    什么是聚合? 聚合 可以让我们极其方便的实现对数据的统计、分析、运算。例如: 什么 品牌 的手机最受欢迎? 这些手机的 平均 价格、 最高 价格、 最低 价格? 这些手机每 月的销售情况 如何? 实现这些统计功能的比数据库的sql要方便的多,而且查询速度非常快,可以实

    2024年02月07日
    浏览(44)
  • 分布式搜索分析引擎ES

    es是实时的分布式搜索分析引擎: 实时表现在新增到ES中的数据1s中就可以被检索到,这种新增数据对搜索的可见性成为“准实时搜索”。 分布式意味着可以动态调整集群规模,弹性扩容,支持上百个节点,相比 HDFS 等上千台的集群,更适合中等数据量的业务,不适合存储海

    2024年03月12日
    浏览(46)
  • 分布式搜索引擎es 面试突击

    es elastocsearch 倒排索引 是在数据查询之前建立,在查询的时候可以直接通过定位到文档内容。用空间换时间 分布式架构原理说一下? es底层是基于lucene来的   大概就是一个用于全文检索的jar包 用es来做分布式的搜索引擎  可以承载一秒钟几千的搜索 es用来存储数据的

    2024年02月06日
    浏览(40)
  • ElasticSearch内容分享(四):ES搜索引擎

    目录 ES搜索引擎 1. DSL设置查询条件 1.1 DSL查询分类 1.2 全文检索查询 1.2.1 使用场景 1.2.2 match查询 1.2.3 mulit_match查询 1.3 精准查询 1.3.1 term查询 1.3.2 range查询 1.4 地理坐标查询 1.4.1 矩形范围查询 1.4.2 附近(圆形)查询 1.5 复合查询 1.5.0 复合查询归纳 1.5.1 相关性算分 1.5.2 算分函数查

    2024年02月05日
    浏览(51)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包