• Elasticsearch 认证模拟题 - 21


    一、题目

    写一个查询,要求查询 kibana_sample_data_ecommerce 索引,且 day_of_weekcustomer_gendercurrencytype 这 4 个字段中至少两个以上。

    1.1 考点
    1. Boolean
    1.2 答案
    GET kibana_sample_data_ecommerce/_search
    {
      "query": {
        "bool": {
          "should": [
            {
              "term": {
                "day_of_week": {
                  "value": "Monday"
                }
              }
            },
            {
              "term": {
                "customer_gender": {
                  "value": "MALE"
                }
              }
            },
            {
              "term": {
                "currency": {
                  "value": "EUR"
                }
              }
            },
            {
              "term": {
                "type": {
                  "value": "order"
                }
              }
            }
          ],
          "minimum_should_match": 2
        }
      }
    }
    

    二、题目

    task 索引中文档的 fieldafieldbfieldc 字段进行查询,并
    要求最终的算分是fieldafieldbfieldc 字段上算分的总和,同时要求对 fieldb 字段设置 boosting

    # 创建符合条件的 task 索引,设置 field 字段,并写入数据
    PUT task
    {
      "mappings": {
        "properties": {
          "fielda":{
            "type": "text"
          },
          "fieldb":{
            "type": "text"
          },
          "fieldc":{
            "type": "text"
          },
          "fieldd":{
            "type": "long"
          }
        }
      }
    }
    
    # 写入数据
    POST task/_bulk
    {"index":{}}
    {"fielda":"中国人民广场", "fieldb":"天安门", "fieldc":"中国人民广场", "fieldd": 5}
    {"index":{}}
    {"fielda":"中华人民共和国万岁", "fieldb":"日月潭", "fieldc":"中国人民广场", "fieldd": 6}
    {"index":{}}
    {"fielda":"山上山下红旗飘飘", "fieldb":"农民翻身把歌唱", "fieldc":"中国人民广场", "fieldd": 4}
    {"index":{}}
    {"fielda":"中国共产党万岁", "fieldb":"中国人民广场", "fieldc":"中国人民广场", "fieldd": 5}
    {"index":{}}
    {"fielda":"春眠不觉晓", "fieldb":"中国人民", "fieldc":"处处闻啼鸟", "fieldd": 5}
    
    2.1 考点
    1. Multi-match
    2.2 答案
    GET task/_search
    {
      "query": {
        "multi_match" : {
          "query" : "中华人民",
          "fields" : [ "fielda", "fieldb^2", "fieldc"] 
        }
      }
    }
    

    在这里插入图片描述

    这里更新一个 分数的计算方式

    GET task/_search
    {
      "query": {
        "multi_match" : {
          "query" : "中华人民",
          "fields" : [ "fielda", "fieldb^2", "fieldc"],
          "type": "most_fields"
        }
      }
    }
    

    在这里插入图片描述

  • 相关阅读:
    如何使用代码来构造HTTP请求?
    冒泡排序及其优化
    Zookeeper经典应用场景实战(一)
    Redo Log Undo Log 与 Bin Log介绍
    在 Azure AKS 上部署 EMQX MQTT 服务器集群
    旋转的骰子(二)
    LeetCode(剑指 Offer)- 25. 合并两个排序的链表
    Golang Gorm 一对多 关联模式 Association + Find 查询关联
    JVM虚拟机——类加载器(JDK8及以前,打破双亲委派机制)(JDK9之后的类加载器)
    使用Flink1.16.0的SQLGateway迁移Hive SQL任务
  • 原文地址:https://blog.csdn.net/Wolf_xujie/article/details/139657836