tencent cloud


SCF + ES for Quick Search Service

Last updated: 2023-04-27 17:50:06

    Search Service

    Search services are everywhere, such as Google search in daily life, wiki search in work, and product search in shopping. Data in such scenarios is generally large in size and structured and has more reads than writes. However, due to their transaction characteristics, traditional databases cannot well utilize space in search scenarios and are slow in full-text searches (such as LIKE statement). Elasticsearch thus came into being.
    Elasticsearch is an open-source search engine widely used in full-text search. It can quickly index, search, and analyze a massive amount of text data. Tencent Cloud ES is a highly available and scalable cloud-hosted Elasticsearch service. It well supports both structured and non-structured data and provides easy-to-use RESTful APIs and clients in multiple languages to help you quickly build stable search services.
    This document describes how to use ES and SCF to quickly build a search service by referring to the official Tencent Cloud ES documentation.

    Resource Preparations

    Purchase an ES cluster. The cluster scale is subject to the search service QPS and data size of the stored documents. For more information, see Evaluation of Cluster Specification and Capacity Configuration.

    Deploying Search Service

    Use SCF to deploy the frontend page and backend service of the search service.
    1. In the top-left corner of the Functions page in the SCF console, select the region of the purchased ES cluster.
    2. Click Create to create a function service as instructed in Create a Function.
    3. After the function is created, click Function name to enter the function details page.
    4. On the Function configuration page, click Edit in the top-right corner, enable Private network access, select the VPC selected during ES cluster creation, and click Save.
    5. Click Code ZIP package to download the sample file.
    6. In Submitting method on the Function codes page, select Upload local ZIP package, select the ZIP package just downloaded, and click Deploy.
    7. Modify the code on the Function Code page. You need to modify the index.py and index.html files:
    Change es_endpoint in index.py to the private network address of your ES cluster, such as
    Change es_password in index.py to the password of ES Platinum Edition; if your ES is not Platinum Edition, leave it unchanged.
    Change server_name in index.html to the name of the created SCF function, which is myserver by default.
    es_corpus_0126 is used as the index name by default in the sample. Make sure that the index is not used by other businesses. To modify it, modify the es_index variable in index.py.
    8. Click Add trigger method on the Trigger method page, add an API Gateway trigger as shown below, enable integration response, and click Save.
    9. View the function access path in Trigger method and access the page by clicking the path.
    10. Upload the sample data of Elasticsearch Service. Click the text above the search box to automatically import data.
    11. At this point, you have deployed a simple ES-based Q&A search service backend.

    Learn More

    Importing stopword and custom dictionary

    Stopwords will not be searched by ES, and words in the custom dictionary will be retained during segmentation. In the previous sample, the default stopword dictionary and custom dictionary are imported. You can also import your own stopword and custom dictionaries in Plugin List > Update Dictionary on the ES cluster details page.

    Synonym configuration

    To configure synonyms, you need to specify them when creating an index. Synonyms in Solr and WordNet formats are supported. For more information on the format, see Solr synonyms.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support