文档

在Kibana中对Serverless应用中的数据进行检索、查询

更新时间:

本文介绍在Kibana中对Elasticsearch Serverless应用中的数据进行全文检索、多语言检索和地理位置查询。

背景信息

Elasticsearch Serverless服务是围绕Elasticsearch打造的云原生Serverless服务化产品,用户无需管理集群和配置资源即可实现业务负载与资源动态匹配。支持弹性扩缩,在业务高峰期也能满足需求。保留用户原有使用习惯,支持平滑切换和使用,助力业务快速上云。

准备工作

  1. 创建Serverless应用。具体操作,请参见创建应用

    说明

    第一次使用Elasticsearch Serverless服务需要根据页面提示开通Elasticsearch Serverless服务。

  2. 登录Kibana。具体操作,请参见使用Kibana

    说明

    登录前需要将待登录Kibana的设备的IP地址加入到应用公网访问Kibana的白名单中。具体操作,请参见配置公网访问白名单

  3. 在Kibana控制台的左上角,选择菜单.png > Management > Dev Tools

    您可以在Console中执行代码,完成数据插入、检索等操作。

全文检索

Elasticsearch Serverless服务是一个基于Lucene的实时的分布式搜索和分析引擎,用于云计算中能够实现实时、稳定、可靠、快速的搜索和分析。

  1. 创建product_info索引并插入数据。

    1. 创建索引。

      PUT /product_info
      {
        "mappings": {
            "properties": {
              "productName": {
                "type": "text",
                "analyzer": "ik_smart"
              },
              "annual_rate":{
                "type":"keyword"
              },
              "describe": {
                "type": "text",
                "analyzer": "ik_smart"
              }
          }
        }
      }
    2. 使用bulk方式在索引中插入数据。

      POST /product_info/_doc/_bulk
      {"index":{}}
      {"productName":"理财产品A","annual_rate":"3.2200%","describe":"180天定期理财,最低20000起投,收益稳定,可以自助选择消息推送"}
      {"index":{}}
      {"productName":"理财产品B","annual_rate":"3.1100%","describe":"90天定投产品,最低10000起投,每天收益到账消息推送"}
      {"index":{}}
      {"productName":"理财产品C","annual_rate":"3.3500%","describe":"270天定投产品,最低40000起投,每天收益立即到账消息推送"}
      {"index":{}}
      {"productName":"理财产品D","annual_rate":"3.1200%","describe":"90天定投产品,最低12000起投,每天收益到账消息推送"}
      {"index":{}}
      {"productName":"理财产品E","annual_rate":"3.0100%","describe":"30天定投产品推荐,最低8000起投,每天收益会消息推送"}
      {"index":{}}
      {"productName":"理财产品F","annual_rate":"2.7500%","describe":"热门短期产品,3天短期,无须任何手续费用,最低500起投,通过短信提示获取收益消息"}
  2. 查询数据

    1. 搜索产品信息文档中包含每天收益到账消息推送的所有产品。

      GET /product_info/_doc/_search
      {
        "query": {
          "match": {
            "describe": "每天收益到账消息推送"
          }
        }
      }

      返回结果如下:

      {
        "took" : 8,
        "timed_out" : false,
        "_shards" : {
          "total" : 3,
          "successful" : 3,
          "skipped" : 0,
          "failed" : 0
        },
        "hits" : {
          "total" : {
            "value" : 6,
            "relation" : "eq"
          },
          "max_score" : 1.87463,
          "hits" : [
            {
              "_index" : "product_info",
              "_type" : "_doc",
              "_id" : "mEWajIoBaH-7DHixr9am",
              "_score" : 1.87463,
              "_source" : {
                "productName" : "理财产品E",
                "annual_rate" : "3.0100%",
                "describe" : "30天定投产品推荐,最低8000起投,每天收益会消息推送"
              }
            },
            {
              "_index" : "product_info",
              "_type" : "_doc",
              "_id" : "lUWajIoBaH-7DHixr9am",
              "_score" : 1.8293141,
              "_source" : {
                "productName" : "理财产品B",
                "annual_rate" : "3.1100%",
                "describe" : "90天定投产品,最低10000起投,每天收益到账消息推送"
              }
            },
            {
              "_index" : "product_info",
              "_type" : "_doc",
              "_id" : "lkWajIoBaH-7DHixr9am",
              "_score" : 1.7743123,
              "_source" : {
                "productName" : "理财产品C",
                "annual_rate" : "3.3500%",
                "describe" : "270天定投产品,最低40000起投,每天收益立即到账消息推送"
              }
            },
            {
              "_index" : "product_info",
              "_type" : "_doc",
              "_id" : "l0WajIoBaH-7DHixr9am",
              "_score" : 1.7260926,
              "_source" : {
                "productName" : "理财产品D",
                "annual_rate" : "3.1200%",
                "describe" : "90天定投产品,最低12000起投,每天收益到账消息推送"
              }
            },
            {
              "_index" : "product_info",
              "_type" : "_doc",
              "_id" : "lEWajIoBaH-7DHixr9am",
              "_score" : 0.40473348,
              "_source" : {
                "productName" : "理财产品A",
                "annual_rate" : "3.2200%",
                "describe" : "180天定期理财,最低20000起投,收益稳定,可以自助选择消息推送"
              }
            },
            {
              "_index" : "product_info",
              "_type" : "_doc",
              "_id" : "mUWajIoBaH-7DHixr9am",
              "_score" : 0.3420724,
              "_source" : {
                "productName" : "理财产品F",
                "annual_rate" : "2.7500%",
                "describe" : "热门短期产品,3天短期,无须任何手续费用,最低500起投,通过短信提示获取收益消息"
              }
            }
          ]
        }
      }
      
    2. 筛查年利率在3.0000%到3.1000%之间的产品。

      GET /product_info/_doc/_search
      {
        "query": {
          "range": {
            "annual_rate": {
              "gte": "3.0000%",
              "lte": "3.1000%"
            }
          }
        }
      }

      返回结果如下:

      {
        "took" : 8,
        "timed_out" : false,
        "_shards" : {
          "total" : 3,
          "successful" : 3,
          "skipped" : 0,
          "failed" : 0
        },
        "hits" : {
          "total" : {
            "value" : 1,
            "relation" : "eq"
          },
          "max_score" : 1.0,
          "hits" : [
            {
              "_index" : "product_info",
              "_type" : "_doc",
              "_id" : "mEWajIoBaH-7DHixr9am",
              "_score" : 1.0,
              "_source" : {
                "productName" : "理财产品E",
                "annual_rate" : "3.0100%",
                "describe" : "30天定投产品推荐,最低8000起投,每天收益会消息推送"
              }
            }
          ]
        }
      }
      

多语言检索

多语言检索在Elasticsearch Serverless服务上应用很广泛。

英文全文搜索

  1. 创建english_index索引并插入数据。

    1. 创建索引。

      PUT /english_index
      {
        "mappings": {
            "properties": {
              "text": {
                "type": "text"
              }     
            }
          }
        }
    2. 在索引中插入数据。

      POST /_bulk
      { "index":  { "_index": "english_index","_id": "1" }}
      { "text" : "Hangzhou, referred to as \"Hangzhou\", formerly known as Lin 'an and Qiantang, is a prefecture-level city, provincial capital, sub-provincial city, mega-city of Zhejiang Province, the core city of Hangzhou metropolitan area, the economic, cultural, scientific and educational center of Zhejiang Province approved by The State Council, and one of the central cities of the Yangtze River Delta. As of 2019, the city has jurisdiction over 10 municipal districts, 2 counties and 1 county-level city, with a total area of 16,850 square kilometers and a built-up area of 648.46 square kilometers. By the end of 2021, Hangzhou had a permanent population of 12.204 million. In 2021, the city's GDP reached 1,810.9 billion yuan." }
      { "index":  { "_index": "english_index","_id": "2" }}
      { "text" : "Hangzhou is one of the first national historical and cultural cities, known as the \"Southeast county\" in the world. Excavations at the Trans-Lake Bridge site show that humans lived here more than 8,000 years ago. The Liangzhu Culture dating back more than 5,000 years is known as the \"dawn of Chinese civilization\". Hangzhou has a history of more than 2,200 years since it was established as a county in the Qin Dynasty. It was once the capital of the Wu Yue State and the Southern Song Dynasty." }
      { "index":  { "_index": "english_index","_id": "3" }}
      { "text" : "Hangzhou is located in East China, the lower reaches of Qiantang River, the southeast coast, the north of Zhejiang Province, and the southern end of the Beijing-Hangzhou Grand Canal. The geographical coordinates are between 29°11 '-30 °34' N and 118°20 '-120 °37' E. Hangzhou is the core city of the Hangzhou Bay Greater Bay Area and the center city of the G60 Science and Innovation Corridor. Hangzhou has numerous cultural and historical sites. There are a large number of natural and cultural landscape relics in and around the West Lake, representative of which are West Lake culture, Liangzhu culture, silk culture and tea culture." }
      { "index":  { "_index": "english_index","_id": "4" }}
      { "text" : "Hangzhou is known as \"heaven on earth\" because of its beautiful scenery. Thanks to the convenience of the Beijing-Hangzhou Grand Canal and treaty ports, as well as its own developed silk and grain industries, Hangzhou was historically an important commercial distribution center. Since the new century, with the drive of Alibaba and other high-tech enterprises, the Internet economy has become a new economic growth point in Hangzhou. Hangzhou hosted the 2016 G20 Summit, the 2018 World Short Course Swimming Championships and the 2022 Asian Games. Hangzhou ranked 5th in China's Top 100 Cities list in 2020." }
  2. 搜索数据并查看搜索结果。

    1. 搜索示例一:

      GET english_index/_search
      {
        "query": {
          "match": {
            "text": "The GDP of Hangzhou is increasing gradually"
          }
        }
      }

      返回结果如下所示,包含搜索内容的_id为1的文件在返回结果的最前面。

      {
        "took" : 5,
        "timed_out" : false,
        "_shards" : {
          "total" : 3,
          "successful" : 3,
          "skipped" : 0,
          "failed" : 0
        },
        "hits" : {
          "total" : {
            "value" : 4,
            "relation" : "eq"
          },
          "max_score" : 2.1957722,
          "hits" : [
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "1",
              "_score" : 2.1957722,
              "_source" : {
                "text" : """Hangzhou, referred to as "Hangzhou", formerly known as Lin 'an and Qiantang, is a prefecture-level city, provincial capital, sub-provincial city, mega-city of Zhejiang Province, the core city of Hangzhou metropolitan area, the economic, cultural, scientific and educational center of Zhejiang Province approved by The State Council, and one of the central cities of the Yangtze River Delta. As of 2019, the city has jurisdiction over 10 municipal districts, 2 counties and 1 county-level city, with a total area of 16,850 square kilometers and a built-up area of 648.46 square kilometers. By the end of 2021, Hangzhou had a permanent population of 12.204 million. In 2021, the city's GDP reached 1,810.9 billion yuan."""
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "3",
              "_score" : 0.92763716,
              "_source" : {
                "text" : "Hangzhou is located in East China, the lower reaches of Qiantang River, the southeast coast, the north of Zhejiang Province, and the southern end of the Beijing-Hangzhou Grand Canal. The geographical coordinates are between 29°11 '-30 °34' N and 118°20 '-120 °37' E. Hangzhou is the core city of the Hangzhou Bay Greater Bay Area and the center city of the G60 Science and Innovation Corridor. Hangzhou has numerous cultural and historical sites. There are a large number of natural and cultural landscape relics in and around the West Lake, representative of which are West Lake culture, Liangzhu culture, silk culture and tea culture."
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "2",
              "_score" : 0.87203753,
              "_source" : {
                "text" : """Hangzhou is one of the first national historical and cultural cities, known as the "Southeast county" in the world. Excavations at the Trans-Lake Bridge site show that humans lived here more than 8,000 years ago. The Liangzhu Culture dating back more than 5,000 years is known as the "dawn of Chinese civilization". Hangzhou has a history of more than 2,200 years since it was established as a county in the Qin Dynasty. It was once the capital of the Wu Yue State and the Southern Song Dynasty."""
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "4",
              "_score" : 0.8462847,
              "_source" : {
                "text" : """Hangzhou is known as "heaven on earth" because of its beautiful scenery. Thanks to the convenience of the Beijing-Hangzhou Grand Canal and treaty ports, as well as its own developed silk and grain industries, Hangzhou was historically an important commercial distribution center. Since the new century, with the drive of Alibaba and other high-tech enterprises, the Internet economy has become a new economic growth point in Hangzhou. Hangzhou hosted the 2016 G20 Summit, the 2018 World Short Course Swimming Championships and the 2022 Asian Games. Hangzhou ranked 5th in China's Top 100 Cities list in 2020."""
              }
            }
          ]
        }
      }
      
    2. 搜索示例二:

      GET english_index/_search
      {
        "query": {
          "match": {
            "text": "Hangzhou is one of the top 100 cities"
          }
        }
      }

      返回结果如下所示,包含搜索内容的_id为4的文件在返回结果的最前面。

      {
        "took" : 7,
        "timed_out" : false,
        "_shards" : {
          "total" : 3,
          "successful" : 3,
          "skipped" : 0,
          "failed" : 0
        },
        "hits" : {
          "total" : {
            "value" : 4,
            "relation" : "eq"
          },
          "max_score" : 3.2950416,
          "hits" : [
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "4",
              "_score" : 3.2950416,
              "_source" : {
                "text" : """Hangzhou is known as "heaven on earth" because of its beautiful scenery. Thanks to the convenience of the Beijing-Hangzhou Grand Canal and treaty ports, as well as its own developed silk and grain industries, Hangzhou was historically an important commercial distribution center. Since the new century, with the drive of Alibaba and other high-tech enterprises, the Internet economy has become a new economic growth point in Hangzhou. Hangzhou hosted the 2016 G20 Summit, the 2018 World Short Course Swimming Championships and the 2022 Asian Games. Hangzhou ranked 5th in China's Top 100 Cities list in 2020."""
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "1",
              "_score" : 2.488573,
              "_source" : {
                "text" : """Hangzhou, referred to as "Hangzhou", formerly known as Lin 'an and Qiantang, is a prefecture-level city, provincial capital, sub-provincial city, mega-city of Zhejiang Province, the core city of Hangzhou metropolitan area, the economic, cultural, scientific and educational center of Zhejiang Province approved by The State Council, and one of the central cities of the Yangtze River Delta. As of 2019, the city has jurisdiction over 10 municipal districts, 2 counties and 1 county-level city, with a total area of 16,850 square kilometers and a built-up area of 648.46 square kilometers. By the end of 2021, Hangzhou had a permanent population of 12.204 million. In 2021, the city's GDP reached 1,810.9 billion yuan."""
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "2",
              "_score" : 2.3840938,
              "_source" : {
                "text" : """Hangzhou is one of the first national historical and cultural cities, known as the "Southeast county" in the world. Excavations at the Trans-Lake Bridge site show that humans lived here more than 8,000 years ago. The Liangzhu Culture dating back more than 5,000 years is known as the "dawn of Chinese civilization". Hangzhou has a history of more than 2,200 years since it was established as a county in the Qin Dynasty. It was once the capital of the Wu Yue State and the Southern Song Dynasty."""
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "3",
              "_score" : 0.92763716,
              "_source" : {
                "text" : "Hangzhou is located in East China, the lower reaches of Qiantang River, the southeast coast, the north of Zhejiang Province, and the southern end of the Beijing-Hangzhou Grand Canal. The geographical coordinates are between 29°11 '-30 °34' N and 118°20 '-120 °37' E. Hangzhou is the core city of the Hangzhou Bay Greater Bay Area and the center city of the G60 Science and Innovation Corridor. Hangzhou has numerous cultural and historical sites. There are a large number of natural and cultural landscape relics in and around the West Lake, representative of which are West Lake culture, Liangzhu culture, silk culture and tea culture."
              }
            }
          ]
        }
      }
      
    3. 搜索示例三:

      GET english_index/_search
      {
        "query": {
          "match": {
            "text": "Hangzhou is one of the first national historical and cultural city"
          }
        }
      }

      返回结果如下所示,包含搜索内容的_id为2的文件在返回结果的最前面。

      {
        "took" : 5,
        "timed_out" : false,
        "_shards" : {
          "total" : 3,
          "successful" : 3,
          "skipped" : 0,
          "failed" : 0
        },
        "hits" : {
          "total" : {
            "value" : 4,
            "relation" : "eq"
          },
          "max_score" : 5.107232,
          "hits" : [
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "2",
              "_score" : 5.107232,
              "_source" : {
                "text" : """Hangzhou is one of the first national historical and cultural cities, known as the "Southeast county" in the world. Excavations at the Trans-Lake Bridge site show that humans lived here more than 8,000 years ago. The Liangzhu Culture dating back more than 5,000 years is known as the "dawn of Chinese civilization". Hangzhou has a history of more than 2,200 years since it was established as a county in the Qin Dynasty. It was once the capital of the Wu Yue State and the Southern Song Dynasty."""
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "3",
              "_score" : 3.5984995,
              "_source" : {
                "text" : "Hangzhou is located in East China, the lower reaches of Qiantang River, the southeast coast, the north of Zhejiang Province, and the southern end of the Beijing-Hangzhou Grand Canal. The geographical coordinates are between 29°11 '-30 °34' N and 118°20 '-120 °37' E. Hangzhou is the core city of the Hangzhou Bay Greater Bay Area and the center city of the G60 Science and Innovation Corridor. Hangzhou has numerous cultural and historical sites. There are a large number of natural and cultural landscape relics in and around the West Lake, representative of which are West Lake culture, Liangzhu culture, silk culture and tea culture."
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "1",
              "_score" : 3.5324125,
              "_source" : {
                "text" : """Hangzhou, referred to as "Hangzhou", formerly known as Lin 'an and Qiantang, is a prefecture-level city, provincial capital, sub-provincial city, mega-city of Zhejiang Province, the core city of Hangzhou metropolitan area, the economic, cultural, scientific and educational center of Zhejiang Province approved by The State Council, and one of the central cities of the Yangtze River Delta. As of 2019, the city has jurisdiction over 10 municipal districts, 2 counties and 1 county-level city, with a total area of 16,850 square kilometers and a built-up area of 648.46 square kilometers. By the end of 2021, Hangzhou had a permanent population of 12.204 million. In 2021, the city's GDP reached 1,810.9 billion yuan."""
              }
            },
            {
              "_index" : "english_index",
              "_type" : "_doc",
              "_id" : "4",
              "_score" : 1.0729303,
              "_source" : {
                "text" : """Hangzhou is known as "heaven on earth" because of its beautiful scenery. Thanks to the convenience of the Beijing-Hangzhou Grand Canal and treaty ports, as well as its own developed silk and grain industries, Hangzhou was historically an important commercial distribution center. Since the new century, with the drive of Alibaba and other high-tech enterprises, the Internet economy has become a new economic growth point in Hangzhou. Hangzhou hosted the 2016 G20 Summit, the 2018 World Short Course Swimming Championships and the 2022 Asian Games. Hangzhou ranked 5th in China's Top 100 Cities list in 2020."""
              }
            }
          ]
        }
      }
      

法文全文搜索

  1. 创建french_index索引并插入数据。

    1. 创建索引。

      PUT /french_index
      {
        "mappings": {
            "properties": {
              "text": {
                "type": "text",
                "analyzer": "french"
              }
          }
        }
      }
    2. 在索引中插入数据。

      POST /_bulk
      { "index":  { "_index": "french_index","_id": "1" }}
      { "text" : "Hangzhou, appelé «hang», anciennement connu sous le nom de linan et qiantang, la ville de la province de zhejiang, la capitale de la province, la ville vice-provinciale, la mégapole, la ville du noyau de la zone métropolitaine de hangzhou, le conseil d’état a approuvé et identifié le centre économique, culturel, scientifique et éducatif de la province de zhejiang, l’une des villes du centre du delta du yangtze. À partir de 2019, la ville est administrée par 10 districts municipaux, 2 comtés et une municipalité au niveau de comté. La superficie totale de la ville est de 16850 kilomètres carrés et la zone bâtie de 648,46 kilomètres carrés. À la fin de 2021, la ville de hangzhou a une population permanente de 12 204 000 personnes. En 2021, la ville a réalisé un produit régional brut de 1810,9 milliards de yuans." }
      { "index":  { "_index": "french_index","_id": "2" }}
      { "text" : "Hangzhou est l’une des premières villes historiques et culturelles nationales, célèbre pour son comté célèbre du sud-est. Les fouilles sur le site du pont trans-lac ont révélé que des humains y ont peuplé il y a plus de 8000 ans. La culture liangzhu, qui date de plus de 5000 ans, est appelée «l’aube de la civilisation chinoise». Hangzhou a une histoire de plus de 2200 ans depuis la création du comté sous la dynastie qin. Hangzhou a été la capitale de wuyue et de song du sud." }
      { "index":  { "_index": "french_index","_id": "3" }}
      { "text" : "Hangzhou est située dans la région de l’est de la Chine, en aval de la rivière qiantang, sur la côte sud-est, au nord du zhejiang et à l’extrémité sud du grand canal de pékin hangzhou. Ses coordonnées géographiques se situent entre 29° 11’ - 30° 34’ de latitude nord et 118° 20’ - 120° 37’ de longitude est. Hangzhou est la ville centrale de la grande baie de la baie de hangzhou et la ville centrale du corridor G60 kochuang. Hangzhou a de nombreux monuments humanistes. Il y a un grand nombre de vestiges de paysages naturels et humains dans et autour de xihu. Les représentants sont la culture xihu, la culture liangzhu, la culture de la soie et la culture du thé." }
      { "index":  { "_index": "french_index","_id": "4" }}
      { "text" : "Hangzhou a la réputation de «paradis sur terre» en raison de ses paysages magnifiques. Bénéficiant de la commodité du grand canal de pékin et des ports commerciaux, ainsi que de ses propres industries bien développées de la soie et des céréales, hangzhou a été historiquement un important centre de distribution commerciale. Depuis le nouveau siècle, avec alibaba et d’autres entreprises de haute technologie, l’économie d’internet est devenue le nouveau point de croissance économique de hangzhou. Le sommet du G20 2016, le championnat du monde de natation en piscine courte 2018 et les jeux asiatiques 2022 ont eu lieu à hangzhou. Top 100 des villes chinoises en 2020. Hangzhou est la 5ème." }
  2. 搜索数据并查看搜索结果。

    GET french_index/_search
    {
      "query": {
        "match": {
          "text": "Hangzhou est top 100 des villes chinoises en 2020."
        }
      }
    }

    返回结果如下所示,包含搜索内容的_id为4的文件在返回结果的最前面。

    {
      "took" : 11,
      "timed_out" : false,
      "_shards" : {
        "total" : 3,
        "successful" : 3,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 4,
          "relation" : "eq"
        },
        "max_score" : 3.7113173,
        "hits" : [
          {
            "_index" : "french_index",
            "_type" : "_doc",
            "_id" : "4",
            "_score" : 3.7113173,
            "_source" : {
              "text" : "Hangzhou a la réputation de «paradis sur terre» en raison de ses paysages magnifiques. Bénéficiant de la commodité du grand canal de pékin et des ports commerciaux, ainsi que de ses propres industries bien développées de la soie et des céréales, hangzhou a été historiquement un important centre de distribution commerciale. Depuis le nouveau siècle, avec alibaba et d’autres entreprises de haute technologie, l’économie d’internet est devenue le nouveau point de croissance économique de hangzhou. Le sommet du G20 2016, le championnat du monde de natation en piscine courte 2018 et les jeux asiatiques 2022 ont eu lieu à hangzhou. Top 100 des villes chinoises en 2020. Hangzhou est la 5ème."
            }
          },
          {
            "_index" : "french_index",
            "_type" : "_doc",
            "_id" : "1",
            "_score" : 1.0079018,
            "_source" : {
              "text" : "Hangzhou, appelé «hang», anciennement connu sous le nom de linan et qiantang, la ville de la province de zhejiang, la capitale de la province, la ville vice-provinciale, la mégapole, la ville du noyau de la zone métropolitaine de hangzhou, le conseil d’état a approuvé et identifié le centre économique, culturel, scientifique et éducatif de la province de zhejiang, l’une des villes du centre du delta du yangtze. À partir de 2019, la ville est administrée par 10 districts municipaux, 2 comtés et une municipalité au niveau de comté. La superficie totale de la ville est de 16850 kilomètres carrés et la zone bâtie de 648,46 kilomètres carrés. À la fin de 2021, la ville de hangzhou a une population permanente de 12 204 000 personnes. En 2021, la ville a réalisé un produit régional brut de 1810,9 milliards de yuans."
            }
          },
          {
            "_index" : "french_index",
            "_type" : "_doc",
            "_id" : "2",
            "_score" : 0.8698735,
            "_source" : {
              "text" : "Hangzhou est l’une des premières villes historiques et culturelles nationales, célèbre pour son comté célèbre du sud-est. Les fouilles sur le site du pont trans-lac ont révélé que des humains y ont peuplé il y a plus de 8000 ans. La culture liangzhu, qui date de plus de 5000 ans, est appelée «l’aube de la civilisation chinoise». Hangzhou a une histoire de plus de 2200 ans depuis la création du comté sous la dynastie qin. Hangzhou a été la capitale de wuyue et de song du sud."
            }
          },
          {
            "_index" : "french_index",
            "_type" : "_doc",
            "_id" : "3",
            "_score" : 0.4163319,
            "_source" : {
              "text" : "Hangzhou est située dans la région de l’est de la Chine, en aval de la rivière qiantang, sur la côte sud-est, au nord du zhejiang et à l’extrémité sud du grand canal de pékin hangzhou. Ses coordonnées géographiques se situent entre 29° 11’ - 30° 34’ de latitude nord et 118° 20’ - 120° 37’ de longitude est. Hangzhou est la ville centrale de la grande baie de la baie de hangzhou et la ville centrale du corridor G60 kochuang. Hangzhou a de nombreux monuments humanistes. Il y a un grand nombre de vestiges de paysages naturels et humains dans et autour de xihu. Les représentants sont la culture xihu, la culture liangzhu, la culture de la soie et la culture du thé."
            }
          }
        ]
      }
    }
    

支持检索多种语言

Elasticsearch Serverless服务支持汉语、英语、法语、德语、俄语、日语、韩语、越语、缅语等主要语言。

  1. 创建language对象。

    POST language/_doc
    {
      "中文": "中文",
      "英语": "english",
      "法语": "Français",
      "德语": "Deutsch",
      "日语": "にほんご",
      "俄语": "Русский язык",
      "韩语": "한국어",
      "越南语": "Tiếng Việt",
      "缅甸语": "မြန်မာဘာသာ"
    }
  2. 搜索language对象。

    GET language/_search

    返回结果如下所示,返回结果与插入的数据是一致的。

    {
      "took" : 2,
      "timed_out" : false,
      "_shards" : {
        "total" : 3,
        "successful" : 3,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "language",
            "_type" : "_doc",
            "_id" : "MUVBjYoBaH-7DHixjus2",
            "_score" : 1.0,
            "_source" : {
              "中文" : "中文",
              "英语" : "english",
              "法语" : "Français",
              "德语" : "Deutsch",
              "日语" : "にほんご",
              "俄语" : "Русский язык",
              "韩语" : "한국어",
              "越南语" : "Tiếng Việt",
              "缅甸语" : "မြန်မာဘာသာ"
            }
          }
        ]
      }
    }
    

地理位置查询

基于地理位置信息的应用非常多,例如,通过当前位置信息搜索附近的人。下面主要介绍在阿里云Elasticsearch Serverless服务上进行基于位置信息的检索。

  1. 创建索引并写入数据。

    1. 创建索引attractions,指定userid为keyword字段,locationname为text字段,location为geo_point字段,accesstime为date字段。

      PUT /attractions
      {
        "mappings": {
            "properties": {
      	    "userid": {
                "type": "keyword"
              },
              "locationname": {
                "type": "text"
              },
              "location": {
                "type": "geo_point"
              },
      		"accesstime": {
                "type": "date",
      		  "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
              }
            }
        }
      }
    2. 通过bulk方式插入数据。

      POST /_bulk
      { "index":  { "_index": "attractions","_id": "1" }}
      {"userid": "001", "locationname": "颐和园", "location":[116.273987,39.992019], "accesstime": "2021-05-01 10:30:00"}
      { "index":  { "_index": "attractions","_id": "2" }}
      {"userid": "002", "locationname": "中关村", "location":[116.326933,39.981078], "accesstime": "2021-05-02 14:45:30"}
      { "index":  { "_index": "attractions","_id": "3" }}
      {"userid": "003", "locationname": "动物园", "location":[116.338239,39.942547], "accesstime": "2021-05-03 09:20:15"}
      { "index":  { "_index": "attractions","_id": "4" }}
      {"userid": "004", "locationname": "北京大学", "location":[116.319935,39.996275], "accesstime": "2021-05-04 16:55:10"}
      { "index":  { "_index": "attractions","_id": "5" }}
      {"userid": "005", "locationname": "香山公园", "location":[116.191247,39.997232], "accesstime": "2021-05-05 13:00:45"}
      { "index":  { "_index": "attractions","_id": "6" }}
      {"userid": "006", "locationname": "圆明园", "location":[116.309868,40.018307], "accesstime": "2021-05-06 19:10:20"}
  2. 查询数据。

    1. 通过userid,查询用户访问景点的记录。

      GET /attractions/_search
      {
        "query": {
          "query_string": {
            "default_field": "userid",
            "query": "005"
          }
        }
      }

      返回结果如下:

      {
        "took" : 21,
        "timed_out" : false,
        "_shards" : {
          "total" : 3,
          "successful" : 3,
          "skipped" : 0,
          "failed" : 0
        },
        "hits" : {
          "total" : {
            "value" : 1,
            "relation" : "eq"
          },
          "max_score" : 0.2876821,
          "hits" : [
            {
              "_index" : "attractions",
              "_type" : "_doc",
              "_id" : "5",
              "_score" : 0.2876821,
              "_source" : {
                "userid" : "005",
                "locationname" : "香山公园",
                "location" : [
                  116.191247,
                  39.997232
                ],
                "accesstime" : "2021-05-05 13:00:45"
              }
            }
          ]
        }
      }
      
    2. 查询该景点附近10公里范围内的其他景点以及用户的访问时间。

      GET /attractions/_search
      {
       "query": {
         "bool": {
           "filter": {
             "geo_distance": {
               "distance": "10km", 
               "location": { 
                 "lat": 39.997232,
                 "lon": 116.191247
               }
             }
           }
         }
       }
      }

      返回结果如下:

      {
        "took" : 46,
        "timed_out" : false,
        "_shards" : {
          "total" : 3,
          "successful" : 3,
          "skipped" : 0,
          "failed" : 0
        },
        "hits" : {
          "total" : {
            "value" : 2,
            "relation" : "eq"
          },
          "max_score" : 0.0,
          "hits" : [
            {
              "_index" : "attractions",
              "_type" : "_doc",
              "_id" : "5",
              "_score" : 0.0,
              "_source" : {
                "userid" : "005",
                "locationname" : "香山公园",
                "location" : [
                  116.191247,
                  39.997232
                ],
                "accesstime" : "2021-05-05 13:00:45"
              }
            },
            {
              "_index" : "attractions",
              "_type" : "_doc",
              "_id" : "1",
              "_score" : 0.0,
              "_source" : {
                "userid" : "001",
                "locationname" : "颐和园",
                "location" : [
                  116.273987,
                  39.992019
                ],
                "accesstime" : "2021-05-01 10:30:00"
              }
            }
          ]
        }
      }
      

  • 本页导读 (1)
文档反馈