Retrieve and query data in Serverless applications using Kibana

Updated at:

This topic describes how to perform full-text searches, multilingual searches, and geo-queries on data in Elasticsearch Serverless applications using Kibana.

Background information

Elasticsearch Serverless is a cloud-native, serverless product built on Elasticsearch. It dynamically allocates resources based on your business payload, which eliminates the need to manage clusters or configure resources. It supports elastic scaling to accommodate increased demand, even during peak business hours. It is compatible with your existing workflows, supports a smooth transition, and helps you quickly migrate your business to the cloud.

Preparations

  1. Create a search-enhanced application (Version 8.17).

  2. Log on to Kibana.

    Note

    Before you log on, you must add the IP address of your device to the public access whitelist for Kibana.

  3. In the upper-left corner of the Kibana console, choose Menu icon > Management > Dev Tools.

    In the Console, you can run code to perform operations such as inserting and retrieving data.

Full-text search

Based on Lucene, Elasticsearch Serverless is a real-time, distributed search and analysis engine that provides fast, stable, and reliable real-time search and analysis for cloud computing.

  1. Create the product_info index and insert data.

    1. Create the index.

      PUT /product_info
      {
        "mappings": {
            "properties": {
              "productName": {
                "type": "text",
                "analyzer": "ik_smart"
              },
              "annual_rate":{
                "type":"keyword"
              },
              "describe": {
                "type": "text",
                "analyzer": "ik_smart"
              }
          }
        }
      }
    2. Use the bulk API to insert data into the index.

      POST /product_info/_bulk
      {"index":{}}
      {"productName":"Wealth Management Product A","annual_rate":"3.2200%","describe":"180-day fixed-term wealth management, minimum investment of 20,000, stable returns, optional message push notifications"}
      {"index":{}}
      {"productName":"Wealth Management Product B","annual_rate":"3.1100%","describe":"90-day fixed investment product, minimum investment of 10,000, daily earnings message push"}
      {"index":{}}
      {"productName":"Wealth Management Product C","annual_rate":"3.3500%","describe":"270-day fixed investment product, minimum investment of 40,000, immediate daily earnings message push"}
      {"index":{}}
      {"productName":"Wealth Management Product D","annual_rate":"3.1200%","describe":"90-day fixed investment product, minimum investment of 12,000, daily earnings message push"}
      {"index":{}}
      {"productName":"Wealth Management Product E","annual_rate":"3.0100%","describe":"Recommended 30-day fixed investment product, minimum investment of 8,000, daily earnings message push"}
      {"index":{}}
      {"productName":"Wealth Management Product F","annual_rate":"2.7500%","describe":"Popular short-term product, 3-day term, no service fees, minimum investment of 500, receive earnings notifications via text message"}
  2. Query data

    1. Search for all products that have daily earnings message push in their product information document.

      GET /product_info/_search
      {
        "query": {
          "match": {
            "describe": "daily earnings message push"
          }
        }
      }

      The following result is returned:

      {
        "took": 3,
        "timed_out": false,
        "_shards": {
          "total": 1,
          "successful": 1,
          "skipped": 0,
          "failed": 0
        },
        "hits": {
          "total": {
            "value": 6,
            "relation": "eq"
          },
          "max_score": 2.2842526,
          "hits": [
            {
              "_index": "product_info",
              "_id": "_UqOKJkBJUmgCscN7ri0",
              "_score": 2.2842526,
              "_source": {
                "productName": "Wealth Management Product B",
                "annual_rate": "3.1100%",
                "describe": "90-day fixed investment product, minimum investment of 10,000, daily earnings message push"
              }
            },
            {
              "_index": "product_info",
              "_id": "_0qOKJkBJUmgCscN7ri0",
              "_score": 2.2842526,
              "_source": {
                "productName": "Wealth Management Product D",
                "annual_rate": "3.1200%",
                "describe": "90-day fixed investment product, minimum investment of 12,000, daily earnings message push"
              }
            },
            {
              "_index": "product_info",
              "_id": "_kqOKJkBJUmgCscN7ri0",
              "_score": 2.217505,
              "_source": {
                "productName": "Wealth Management Product C",
                "annual_rate": "3.3500%",
                "describe": "270-day fixed investment product, minimum investment of 40,000, immediate daily earnings message push"
              }
            },
            {
              "_index": "product_info",
              "_id": "AEqOKJkBJUmgCscN7rm0",
              "_score": 0.8562305,
              "_source": {
                "productName": "Wealth Management Product E",
                "annual_rate": "3.0100%",
                "describe": "Recommended 30-day fixed investment product, minimum investment of 8,000, daily earnings message push"
              }
            },
            {
              "_index": "product_info",
              "_id": "_EqOKJkBJUmgCscN7ri0",
              "_score": 0.40109843,
              "_source": {
                "productName": "Wealth Management Product A",
                "annual_rate": "3.2200%",
                "describe": "180-day fixed-term wealth management, minimum investment of 20,000, stable returns, optional message push notifications"
              }
            },
            {
              "_index": "product_info",
              "_id": "AUqOKJkBJUmgCscN7rm0",
              "_score": 0.13270499,
              "_source": {
                "productName": "Wealth Management Product F",
                "annual_rate": "2.7500%",
                "describe": "Popular short-term product, 3-day term, no service fees, minimum investment of 500, receive earnings notifications via text message"
              }
            }
          ]
        }
      }
    2. Filter for products with an annual interest rate between 3.0000% and 3.1000%.

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

      The following result is returned:

      {
        "took": 3,
        "timed_out": false,
        "_shards": {
          "total": 1,
          "successful": 1,
          "skipped": 0,
          "failed": 0
        },
        "hits": {
          "total": {
            "value": 1,
            "relation": "eq"
          },
          "max_score": 1,
          "hits": [
            {
              "_index": "product_info",
              "_id": "AEqOKJkBJUmgCscN7rm0",
              "_score": 1,
              "_source": {
                "productName": "Wealth Management Product E",
                "annual_rate": "3.0100%",
                "describe": "Recommended 30-day fixed investment product, minimum investment of 8,000, daily earnings message push"
              }
            }
          ]
        }
      }

Multilingual search

Multilingual search is widely used in Elasticsearch Serverless.

English full-text search

  1. Create the english_index index and insert data.

    1. Create the index.

      PUT /english_index
      {
        "mappings": {
            "properties": {
              "text": {
                "type": "text"
              }     
            }
          }
        }
    2. Insert data into the index.

      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 many 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, along with 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. You can search for data and view the results.

    1. Search example 1:

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

      The following result is returned. The document with an _id of 1 appears first in the results because it contains the search content.

      {
        "took": 7,
        "timed_out": false,
        "_shards": {
          "total": 1,
          "successful": 1,
          "skipped": 0,
          "failed": 0
        },
        "hits": {
          "total": {
            "value": 4,
            "relation": "eq"
          },
          "max_score": 1.8421664,
          "hits": [
            {
              "_index": "english_index",
              "_id": "1",
              "_score": 1.8421664,
              "_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",
              "_id": "3",
              "_score": 0.73713386,
              "_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 many 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",
              "_id": "2",
              "_score": 0.69386226,
              "_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",
              "_id": "4",
              "_score": 0.67353576,
              "_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, along with 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. Search example 2:

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

      The following result is returned. The document with an _id of 4 appears first in the results because it contains the search content.

      {
        "took": 3,
        "timed_out": false,
        "_shards": {
          "total": 1,
          "successful": 1,
          "skipped": 0,
          "failed": 0
        },
        "hits": {
          "total": {
            "value": 4,
            "relation": "eq"
          },
          "max_score": 3.5117872,
          "hits": [
            {
              "_index": "english_index",
              "_id": "4",
              "_score": 3.5117872,
              "_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, along with 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",
              "_id": "2",
              "_score": 1.808171,
              "_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",
              "_id": "1",
              "_score": 1.6936468,
              "_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",
              "_id": "3",
              "_score": 0.73713386,
              "_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 many 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. Search example 3:

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

      The following result is returned. The document with an _id of 2 appears first in the results because it contains the search content.

      {
        "took": 6,
        "timed_out": false,
        "_shards": {
          "total": 1,
          "successful": 1,
          "skipped": 0,
          "failed": 0
        },
        "hits": {
          "total": {
            "value": 4,
            "relation": "eq"
          },
          "max_score": 5.2506256,
          "hits": [
            {
              "_index": "english_index",
              "_id": "2",
              "_score": 5.2506256,
              "_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",
              "_id": "1",
              "_score": 3.1343114,
              "_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",
              "_id": "3",
              "_score": 3.0650156,
              "_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 many 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",
              "_id": "4",
              "_score": 0.85381687,
              "_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, along with 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."""
              }
            }
          ]
        }
      }

French full-text search

  1. Create the french_index index and insert data.

    1. Create the index.

      PUT /french_index
      {
        "mappings": {
            "properties": {
              "text": {
                "type": "text",
                "analyzer": "french"
              }
          }
        }
      }
    2. Insert data into the index.

      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. Search for data and view the search results.

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

    The following result is returned. The document that has an _id of 4 and contains the search term is ranked first in the results.

    {
      "took": 4,
      "timed_out": false,
      "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 4,
          "relation": "eq"
        },
        "max_score": 4.8029723,
        "hits": [
          {
            "_index": "french_index",
            "_id": "4",
            "_score": 4.8029723,
            "_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",
            "_id": "2",
            "_score": 1.2303706,
            "_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",
            "_id": "3",
            "_score": 0.51637566,
            "_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é."
            }
          },
          {
            "_index": "french_index",
            "_id": "1",
            "_score": 0.49398613,
            "_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."
            }
          }
        ]
      }
    }

Support for multiple languages

Elasticsearch Serverless supports major languages such as Chinese, English, French, German, Russian, Japanese, Korean, Vietnamese, and Burmese.

  1. Create a language object.

    POST language/_doc
    {
      "Chinese": "Chinese",
      "English": "english",
      "French": "Français",
      "German": "Deutsch",
      "Japanese": "にほんご",
      "Russian": "Русский язык",
      "Korean": "한국어",
      "Vietnamese": "Tiếng Việt",
      "Burmese": "မြန်မာဘာသာ"
    }
  2. Search the language object.

    GET language/_search

    The following result is returned, which is consistent with the inserted data.

    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 1,
          "relation": "eq"
        },
        "max_score": 1,
        "hits": [
          {
            "_index": "language",
            "_id": "cC-WKJkBN4sqtrqxHJ63",
            "_score": 1,
            "_source": {
              "Chinese": "Chinese",
              "English": "english",
              "French": "Français",
              "German": "Deutsch",
              "Japanese": "にほんご",
              "Russian": "Русский язык",
              "Korean": "한국어",
              "Vietnamese": "Tiếng Việt",
              "Burmese": "မြန်မာဘာသာ"
            }
          }
        ]
      }
    }

Geo query

Applications that use geographic location information are common, such as an application that searches for nearby people based on your current location. This section describes how to run location-based searches in Alibaba Cloud Elasticsearch Serverless.

  1. Create an index and insert data.

    1. Create the attractions index. Specify userid as a keyword field, locationname as a text field, location as a geo_point field, and accesstime as a date field.

      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. Insert data using the bulk API.

      POST /_bulk
      { "index":  { "_index": "attractions","_id": "1" }}
      {"userid": "001", "locationname": "Summer Palace", "location":[116.273987,39.992019], "accesstime": "2021-05-01 10:30:00"}
      { "index":  { "_index": "attractions","_id": "2" }}
      {"userid": "002", "locationname": "Zhongguancun", "location":[116.326933,39.981078], "accesstime": "2021-05-02 14:45:30"}
      { "index":  { "_index": "attractions","_id": "3" }}
      {"userid": "003", "locationname": "Beijing Zoo", "location":[116.338239,39.942547], "accesstime": "2021-05-03 09:20:15"}
      { "index":  { "_index": "attractions","_id": "4" }}
      {"userid": "004", "locationname": "Peking University", "location":[116.319935,39.996275], "accesstime": "2021-05-04 16:55:10"}
      { "index":  { "_index": "attractions","_id": "5" }}
      {"userid": "005", "locationname": "Fragrant Hills Park", "location":[116.191247,39.997232], "accesstime": "2021-05-05 13:00:45"}
      { "index":  { "_index": "attractions","_id": "6" }}
      {"userid": "006", "locationname": "Old Summer Palace", "location":[116.309868,40.018307], "accesstime": "2021-05-06 19:10:20"}
  2. Query data.

    1. Query for the attractions a user has visited based on the userid.

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

      The following result is returned:

      {
        "took": 13,
        "timed_out": false,
        "_shards": {
          "total": 1,
          "successful": 1,
          "skipped": 0,
          "failed": 0
        },
        "hits": {
          "total": {
            "value": 1,
            "relation": "eq"
          },
          "max_score": 1.540445,
          "hits": [
            {
              "_index": "attractions",
              "_id": "5",
              "_score": 1.540445,
              "_source": {
                "userid": "005",
                "locationname": "Fragrant Hills Park",
                "location": [
                  116.191247,
                  39.997232
                ],
                "accesstime": "2021-05-05 13:00:45"
              }
            }
          ]
        }
      }
    2. Query for other attractions and user access times within a 10 km radius of the specified attraction.

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

      The following result is returned:

      {
        "took": 64,
        "timed_out": false,
        "_shards": {
          "total": 1,
          "successful": 1,
          "skipped": 0,
          "failed": 0
        },
        "hits": {
          "total": {
            "value": 2,
            "relation": "eq"
          },
          "max_score": 0,
          "hits": [
            {
              "_index": "attractions",
              "_id": "1",
              "_score": 0,
              "_source": {
                "userid": "001",
                "locationname": "Summer Palace",
                "location": [
                  116.273987,
                  39.992019
                ],
                "accesstime": "2021-05-01 10:30:00"
              }
            },
            {
              "_index": "attractions",
              "_id": "5",
              "_score": 0,
              "_source": {
                "userid": "005",
                "locationname": "Fragrant Hills Park",
                "location": [
                  116.191247,
                  39.997232
                ],
                "accesstime": "2021-05-05 13:00:45"
              }
            }
          ]
        }
      }