All Products
Search
Document Center

OpenSearch:Document search

Last Updated:Feb 13, 2023

Search optimization

This topic describes common issues that you may encounter during the actual search process and how to resolve the issues. If you are unsatisfied with search results or you do not know how to use the search feature, contact Alibaba Cloud for technical support.

The search results depend on the number of documents that hit the keywords in the query. The more documents hit the keywords, the more calculations the system needs to perform, and the longer time is consumed. Therefore, an important optimization method is to reduce the number of documents that are retrieved for a query.

  1. You must specify an index that is created in an application for a query. Otherwise, the default index is used. If the default index does not exist, an error occurs and no results are returned.

    query='mp3' is equivalent to query=default:'mp3'.
  2. The keywords in a query string must be enclosed in single quotation marks (' '). Otherwise, an error may occur and no results may be returned.

    Error:  query=default:mp3
    Right:  query=default:'mp3'
  3. If a keyword contains a curved apostrophe ('), you must escape or remove this character. The last character of a keyword cannot be a backslash (\). Otherwise, this character is used as an escape character, which causes an error. If you need to include a backslash (\) in a query string, you must escape the backslash.

    query=default:'Beijing University' // Documents that contain both Beijing and University are retrieved.
    query=default:'abc's efg' // The query string fails to be parsed and no results are returned. In this case, rewrite the query string to query=default:'abc\'s efg'.
    query=default:'abc\' // An error occurs and no results are returned. The \ character escapes the ' character. In this case, the query string fails to be parsed.
  4. If you need to perform a query to filter fields, we recommend that you create indexes for the fields to be filtered and query the fields by using the query clause. This can improve the query performance.

    query=user_id:'123'&&filter=type_id=1 // Rewrite the query string to query=user_id:'123' AND type_id:'1'.

  5. In some scenarios, you need to query the data of the last month. If the amount of data is large, the query performance is affected. In this case, you can use range search.

    query=user_id:'123'&&filter=time>"2016-09-16" // 50 million data records meet the user_id=123 condition. However, only 1,000 data records are retrieved based on the specified time. If the amount of data that is retrieved for a query is large, a timeout may occur.
    In this case, you can rewrite the query string to the following one:
    query=user_id:'123' AND index_timestamp:(1473955200000,) // Use range query, which is more efficient.

  6. After the specific document is queried, the engine retrieves the actual data that is returned. If the amount of the result data is large, more time is consumed. In this case, you can use the following optimization methods to improve the search effect: Method 1: Reduce the number of documents that are hit. Generally, 20 results are displayed on a page. Method 2: Modify the default display fields or the fetch_fields parameter to return only the fields that are required in the search results.