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"
    }
  }
}

在这里插入图片描述

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值