码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Elasticsearch 认证模拟题 - 22


    一、题目

    索引 task 索引中文档的 fielda 字段内容包括了 hello & world,索引后,要求使用 match_phrase query 查询 hello & world 或者 hello and world 都能匹配该文档

    1.1 考点
    1. 分词器
    1.2 答案
    # 创建符合条件的 task 索引,设置 field 字段,并写入数据
    PUT task
    {
    "settings": {
        "analysis": {
          "analyzer": {
            "my_analyzer": {
              "tokenizer": "standard",
              "char_filter": [
                "my_mappings_char_filter"
              ]
            }
          },
          "char_filter": {
            "my_mappings_char_filter": {
              "type": "mapping",
              "mappings": [
                "& => and"
              ]
            }
          }
        }
      },
      "mappings": {
        "properties": {
          "fielda":{
            "type": "text",
            "analyzer": "my_analyzer"
          }
        }
      }
    }
    
    # 写入数据
    POST task/_bulk
    {"index":{}}
    {"fielda":"hello & world"}
    {"index":{}}
    {"fielda":"hello and world"}
    
    # 验证结果
    GET task/_search
    {
      "query": {
        "match_phrase": {
          "fielda": "hello & world"
        }
      }
    }
    

    二、题目

    有一个索引 task3,其中有 fielda,fieldb,fieldc,fielde 现要求对 task3 重建索引,重建后的索引新增一个字段 fieldg 其值是fielda,fieldb,fieldc,fielde 的值拼接而成。

    # 创建符合条件的 task3 索引,设置 field 字段,并写入数据
    PUT task3
    {
      "mappings": {
        "properties": {
          "fielda":{
            "type": "keyword"
          },
          "fieldb":{
            "type": "keyword"
          },
          "fieldc":{
            "type": "keyword"
          },
          "fielde":{
            "type": "keyword"
          }
        }
      }
    }
    
    POST task3/_bulk
    {"index":{}}
    {"fielda":"aa","fieldb":"bb","fieldc":"cc","fielde":"dd"}
    {"index":{}}
    {"fielda":"中华","fieldb":"人民","fieldc":"共和国","fielde":"万岁"}
    
    2.1 考点
    1. 重建索引
    2. 管道
    2.2 答案
    # 预览脚本结果
    POST _ingest/pipeline/_simulate
    {
      "pipeline": {
        "processors": [
          {
            "script": {
              "lang": "painless",
              "source": """
                ctx['fieldg'] = ctx['fielda'] + ' ' + ctx['fieldb'] + ' '+ctx['fieldc'] + ' ' + ctx['fielde'];
              """
            }
          }
        ]
      },
      "docs": [
        {
          "_source": {
            "fielda":"中华","fieldb":"人民","fieldc":"共和国","fielde":"万岁"
          }
        }
      ]
    }
    
    # 定义脚本
    PUT _ingest/pipeline/my_pipeline
    {
      "processors": [
        {
          "script": {
            "lang": "painless",
            "source": """
                ctx['fieldg'] = ctx['fielda'] + ' ' + ctx['fieldb'] + ' '+ctx['fieldc'] + ' ' + ctx['fielde'];
              """
          }
        }
      ]
    }
    
    # 重建索引
    POST _reindex
    {
      "source": {
        "index": "task3"
      },
      "dest": {
        "index": "task3_new",
        "pipeline": "my_pipeline"
      }
    }
    
    # 搜索结果
    GET task3_new/_search
    

    在这里插入图片描述

  • 相关阅读:
    视频可回溯系统技术方案vue3+ts+tegg+mysql+redis+oss
    29_ue4进阶末日生存游戏开发[准备道具]
    JAVA 递归算法- 椰子汁5元一瓶,4个盖子可以换一瓶椰子汁,3个空瓶可以换一瓶椰子汁,那么 100 块钱可以喝多少瓶椰子汁,剩下瓶盖和空瓶各多少?
    Python数据库sqlite3详解
    k8s pod 绑核
    springboot基于微信小程序“智慧校园” 一体式的设计与实现毕业设计源码091634
    2023-9-22 滑雪
    erron变量、strerror函数 和 perror 函数
    【AUTOSAR】PHM(Platform Health Management)平台健康管理 功能安全模块
    计算机视觉与深度学习-图像分割-视觉识别任务01-语义分割-【北邮鲁鹏】
  • 原文地址:https://blog.csdn.net/Wolf_xujie/article/details/139703922
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号