Ir para o conteúdo

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 )

feita há 2 anos707 visualizações

2 Respostas
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

respondido há 2 anos

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

ESPECIALISTA

respondido há 2 anos

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.