내용으로 건너뛰기

OpenSearch Python client query error: RequestError(400, 'parsing_exception', '[multi_match] unknown token [START_ARRAY] after [query]')

0

I am receiving the following error when running a basic search query against my opensearch domain.

RequestError(400, 'parsing_exception', '[multi_match] unknown token [START_ARRAY] after [query]')

My code is below- it is an example from the OpenSearch docs. Please advise on what could be causing the issue.

(OpenSearch 2.13)

osPort = 443

n = 10 search_phrase = "pizza" osIndex = "index_001"

osClient = OpenSearch( hosts=[{'host': osHost, 'port': osPort}], http_auth=awsauth, use_ssl=True, verify_certs=True, connection_class=RequestsHttpConnection, pool_maxsize=20 ) query = { "size": n, "query": { "multi_match": { "query": search_phrase, "fields": ["fav_food"] } } }

response = osClient.search( index=osIndex, body=query )

질문됨 2년 전704회 조회

2개 답변
0

The error you're encountering suggests that there's an issue with the structure of your query. The specific error message indicates that the OpenSearch engine is expecting a different format for the "multi_match" query.

To resolve this issue, try modifying your query structure slightly. Instead of using a list for the "fields" parameter, use a single string if you're only searching one field. If you need to search multiple fields, you can use a list. Here's the corrected version of your query:

query = {
    "size": n,
    "query": {
        "multi_match": {
            "query": search_phrase,
            "fields": "fav_food"
        }
    }
}

If you need to search multiple fields, you can use a list like this:

"fields": ["fav_food", "other_field", "another_field"]

This modification should resolve the parsing exception you're experiencing. The error occurred because the OpenSearch engine was expecting a string or an array of strings for the "fields" parameter, but encountered an unexpected array start token.

Also, ensure that your index mapping is correctly set up for the fields you're trying to search. If the "fav_food" field is not properly indexed or doesn't exist in your index, you might encounter other issues.

If you continue to experience problems after making these changes, you may want to double-check your index mapping and ensure that the "fav_food" field is properly configured for text searches.
Sources
Common Errors - Amazon OpenSearch Service
Compressing HTTP requests in Amazon OpenSearch Service - Amazon OpenSearch Service

답변함 2년 전

0

Hi, I believe that the error comes from "fields": ["fav_food"] }.

Since you have a single literal value, try "fields": "fav_food"

But, from your code, I guess that you want to achieve something else: fav_food is probably already a list of strings fav_food=["pizza",steak","cake"]. In that case, your code should read "fields": fav_food } with no double quotes to point to the variable fav_food and not a literal value.

Best,

Didier

전문가

답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠