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 the search effect or you do not know how to implement the search feature, contact Alibaba Cloud for technical support.
The search effect depends 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 more time is consumed. Therefore, an important optimization method is to reduce the number of documents that are retrieved for a query.
- 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 can be returned.
query='mp3' is equivalent to query=default:'mp3'.
- 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'
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 it.
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.
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'.
In some scenarios, you need to query the data in 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.
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.