Opensearch/Elasticsearch Must_Not Clause not Accepting a List

I’m trying to write an Opensearch query which will exclude any results which match a list of terms. Per what I can tell in Opensearch documentation, this sort of behavior should be supported.
However, of the two queries I have below, only the one which doesn’t use a list (working_query) works. Unfortunately, googling / searching stackoverflow for the error hasn’t yielded any results that seem relevant. Thanks in advance!

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>working_query = {
"bool": {
"must": [
{
"match_phrase": {
"textContent": {
"query": "must_phrase",
"slop": 10,
}
}
},
{
"bool": {
"should": [
{"match_phrase": {"textContent": "should_phrase"}},
]
}
},
],
"must_not":[
{"match_phrase":{"folderIdentifier.identifierValue":'elem1'}}
],
}
}
</code>
<code>working_query = { "bool": { "must": [ { "match_phrase": { "textContent": { "query": "must_phrase", "slop": 10, } } }, { "bool": { "should": [ {"match_phrase": {"textContent": "should_phrase"}}, ] } }, ], "must_not":[ {"match_phrase":{"folderIdentifier.identifierValue":'elem1'}} ], } } </code>
working_query =  {
    "bool": {
        "must": [
            {
                "match_phrase": {
                    "textContent": {
                        "query": "must_phrase",
                        "slop": 10,
                    }
                }
            },
            {
                "bool": {
                    "should": [
                        {"match_phrase": {"textContent": "should_phrase"}},
                    ]
                }
            },
        ],
        "must_not":[
            {"match_phrase":{"folderIdentifier.identifierValue":'elem1'}}
        ],
    }
}

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>broken_query = {
"bool": {
"must": [
{
"match_phrase": {
"textContent": {
"query": "must_phrase",
"slop": 10,
}
}
},
{
"bool": {
"should": [
{"match_phrase": {"textContent": "should_phrase"}},
]
}
},
],
"must_not":[
{"match_phrase":{"folderIdentifier.identifierValue":['elem1','elem2']}}
],
}
}
</code>
<code>broken_query = { "bool": { "must": [ { "match_phrase": { "textContent": { "query": "must_phrase", "slop": 10, } } }, { "bool": { "should": [ {"match_phrase": {"textContent": "should_phrase"}}, ] } }, ], "must_not":[ {"match_phrase":{"folderIdentifier.identifierValue":['elem1','elem2']}} ], } } </code>
broken_query =  {
    "bool": {
        "must": [
            {
                "match_phrase": {
                    "textContent": {
                        "query": "must_phrase",
                        "slop": 10,
                    }
                }
            },
            {
                "bool": {
                    "should": [
                        {"match_phrase": {"textContent": "should_phrase"}},
                    ]
                }
            },
        ],
        "must_not":[
            {"match_phrase":{"folderIdentifier.identifierValue":['elem1','elem2']}}
        ],
    }
}

Error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>---------------------------------------------------------------------------
RequestError Traceback (most recent call last)
Cell In[56], line 25
1 broken_query = {
2 "bool": {
3 "must": [
(...)
23 }
24 }
---> 25 test=search_docs_full(broken_query)
Cell In[11], line 29, in search_docs_full(text_query)
25 if last_hit != 0:
26 query['search_after'] = [last_hit]
---> 29 results = searchwrapper.client.search(index=index_name,body=query, request_timeout=1200)
30 if len(results['hits']['hits']) != 0:
31 previous_hit = last_hit
File ~/.local/lib/python3.11/site-packages/opensearchpy/client/utils.py:181, in query_params.<locals>._wrapper.<locals>._wrapped(*args, **kwargs)
178 if v is not None:
179 params[p] = _escape(v)
--> 181 return func(*args, params=params, headers=headers, **kwargs)
File ~/.local/lib/python3.11/site-packages/opensearchpy/client/__init__.py:1742, in OpenSearch.search(self, body, index, params, headers)
1739 if "from_" in params:
1740 params["from"] = params.pop("from_")
-> 1742 return self.transport.perform_request(
1743 "POST",
1744 _make_path(index, "_search"),
1745 params=params,
1746 headers=headers,
1747 body=body,
1748 )
File ~/.local/lib/python3.11/site-packages/opensearchpy/transport.py:448, in Transport.perform_request(self, method, url, params, body, timeout, ignore, headers)
446 raise e
447 else:
--> 448 raise e
450 else:
451 # connection didn't fail, confirm its live status
452 self.connection_pool.mark_live(connection)
File ~/.local/lib/python3.11/site-packages/opensearchpy/transport.py:409, in Transport.perform_request(self, method, url, params, body, timeout, ignore, headers)
406 connection = self.get_connection()
408 try:
--> 409 status, headers_response, data = connection.perform_request(
410 method,
411 url,
412 params,
413 body,
414 headers=headers,
415 ignore=ignore,
416 timeout=timeout,
417 )
419 # Lowercase all the header names for consistency in accessing them.
420 headers_response = {
421 header.lower(): value for header, value in headers_response.items()
422 }
File ~/.local/lib/python3.11/site-packages/opensearchpy/connection/http_requests.py:232, in RequestsHttpConnection.perform_request(self, method, url, params, body, timeout, allow_redirects, ignore, headers)
219 if (
220 not (200 <= response.status_code < 300)
221 and response.status_code not in ignore
222 ):
223 self.log_request_fail(
224 method,
225 url,
(...)
230 raw_data,
231 )
--> 232 self._raise_error(
233 response.status_code,
234 raw_data,
235 response.headers.get("Content-Type"),
236 )
238 self.log_request_success(
239 method,
240 url,
(...)
245 duration,
246 )
248 return response.status_code, response.headers, raw_data
File ~/.local/lib/python3.11/site-packages/opensearchpy/connection/base.py:316, in Connection._raise_error(self, status_code, raw_data, content_type)
313 except (ValueError, TypeError) as err:
314 logger.warning("Undecodable raw error response from server: %s", err)
--> 316 raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
317 status_code, error_message, additional_info
318 )
RequestError: RequestError(400, 'x_content_parse_exception', '[1:325] [bool] failed to parse field [must_not]')
</code>
<code>--------------------------------------------------------------------------- RequestError Traceback (most recent call last) Cell In[56], line 25 1 broken_query = { 2 "bool": { 3 "must": [ (...) 23 } 24 } ---> 25 test=search_docs_full(broken_query) Cell In[11], line 29, in search_docs_full(text_query) 25 if last_hit != 0: 26 query['search_after'] = [last_hit] ---> 29 results = searchwrapper.client.search(index=index_name,body=query, request_timeout=1200) 30 if len(results['hits']['hits']) != 0: 31 previous_hit = last_hit File ~/.local/lib/python3.11/site-packages/opensearchpy/client/utils.py:181, in query_params.<locals>._wrapper.<locals>._wrapped(*args, **kwargs) 178 if v is not None: 179 params[p] = _escape(v) --> 181 return func(*args, params=params, headers=headers, **kwargs) File ~/.local/lib/python3.11/site-packages/opensearchpy/client/__init__.py:1742, in OpenSearch.search(self, body, index, params, headers) 1739 if "from_" in params: 1740 params["from"] = params.pop("from_") -> 1742 return self.transport.perform_request( 1743 "POST", 1744 _make_path(index, "_search"), 1745 params=params, 1746 headers=headers, 1747 body=body, 1748 ) File ~/.local/lib/python3.11/site-packages/opensearchpy/transport.py:448, in Transport.perform_request(self, method, url, params, body, timeout, ignore, headers) 446 raise e 447 else: --> 448 raise e 450 else: 451 # connection didn't fail, confirm its live status 452 self.connection_pool.mark_live(connection) File ~/.local/lib/python3.11/site-packages/opensearchpy/transport.py:409, in Transport.perform_request(self, method, url, params, body, timeout, ignore, headers) 406 connection = self.get_connection() 408 try: --> 409 status, headers_response, data = connection.perform_request( 410 method, 411 url, 412 params, 413 body, 414 headers=headers, 415 ignore=ignore, 416 timeout=timeout, 417 ) 419 # Lowercase all the header names for consistency in accessing them. 420 headers_response = { 421 header.lower(): value for header, value in headers_response.items() 422 } File ~/.local/lib/python3.11/site-packages/opensearchpy/connection/http_requests.py:232, in RequestsHttpConnection.perform_request(self, method, url, params, body, timeout, allow_redirects, ignore, headers) 219 if ( 220 not (200 <= response.status_code < 300) 221 and response.status_code not in ignore 222 ): 223 self.log_request_fail( 224 method, 225 url, (...) 230 raw_data, 231 ) --> 232 self._raise_error( 233 response.status_code, 234 raw_data, 235 response.headers.get("Content-Type"), 236 ) 238 self.log_request_success( 239 method, 240 url, (...) 245 duration, 246 ) 248 return response.status_code, response.headers, raw_data File ~/.local/lib/python3.11/site-packages/opensearchpy/connection/base.py:316, in Connection._raise_error(self, status_code, raw_data, content_type) 313 except (ValueError, TypeError) as err: 314 logger.warning("Undecodable raw error response from server: %s", err) --> 316 raise HTTP_EXCEPTIONS.get(status_code, TransportError)( 317 status_code, error_message, additional_info 318 ) RequestError: RequestError(400, 'x_content_parse_exception', '[1:325] [bool] failed to parse field [must_not]') </code>
---------------------------------------------------------------------------
RequestError                              Traceback (most recent call last)
Cell In[56], line 25
      1 broken_query =  {
      2     "bool": {
      3         "must": [
   (...)
     23     }
     24 }
---> 25 test=search_docs_full(broken_query)

Cell In[11], line 29, in search_docs_full(text_query)
     25 if last_hit != 0:
     26     query['search_after'] = [last_hit]
---> 29 results = searchwrapper.client.search(index=index_name,body=query, request_timeout=1200)
     30 if len(results['hits']['hits']) != 0:
     31     previous_hit = last_hit

File ~/.local/lib/python3.11/site-packages/opensearchpy/client/utils.py:181, in query_params.<locals>._wrapper.<locals>._wrapped(*args, **kwargs)
    178         if v is not None:
    179             params[p] = _escape(v)
--> 181 return func(*args, params=params, headers=headers, **kwargs)

File ~/.local/lib/python3.11/site-packages/opensearchpy/client/__init__.py:1742, in OpenSearch.search(self, body, index, params, headers)
   1739 if "from_" in params:
   1740     params["from"] = params.pop("from_")
-> 1742 return self.transport.perform_request(
   1743     "POST",
   1744     _make_path(index, "_search"),
   1745     params=params,
   1746     headers=headers,
   1747     body=body,
   1748 )

File ~/.local/lib/python3.11/site-packages/opensearchpy/transport.py:448, in Transport.perform_request(self, method, url, params, body, timeout, ignore, headers)
    446             raise e
    447     else:
--> 448         raise e
    450 else:
    451     # connection didn't fail, confirm its live status
    452     self.connection_pool.mark_live(connection)

File ~/.local/lib/python3.11/site-packages/opensearchpy/transport.py:409, in Transport.perform_request(self, method, url, params, body, timeout, ignore, headers)
    406 connection = self.get_connection()
    408 try:
--> 409     status, headers_response, data = connection.perform_request(
    410         method,
    411         url,
    412         params,
    413         body,
    414         headers=headers,
    415         ignore=ignore,
    416         timeout=timeout,
    417     )
    419     # Lowercase all the header names for consistency in accessing them.
    420     headers_response = {
    421         header.lower(): value for header, value in headers_response.items()
    422     }

File ~/.local/lib/python3.11/site-packages/opensearchpy/connection/http_requests.py:232, in RequestsHttpConnection.perform_request(self, method, url, params, body, timeout, allow_redirects, ignore, headers)
    219 if (
    220     not (200 <= response.status_code < 300)
    221     and response.status_code not in ignore
    222 ):
    223     self.log_request_fail(
    224         method,
    225         url,
   (...)
    230         raw_data,
    231     )
--> 232     self._raise_error(
    233         response.status_code,
    234         raw_data,
    235         response.headers.get("Content-Type"),
    236     )
    238 self.log_request_success(
    239     method,
    240     url,
   (...)
    245     duration,
    246 )
    248 return response.status_code, response.headers, raw_data

File ~/.local/lib/python3.11/site-packages/opensearchpy/connection/base.py:316, in Connection._raise_error(self, status_code, raw_data, content_type)
    313 except (ValueError, TypeError) as err:
    314     logger.warning("Undecodable raw error response from server: %s", err)
--> 316 raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
    317     status_code, error_message, additional_info
    318 )

RequestError: RequestError(400, 'x_content_parse_exception', '[1:325] [bool] failed to parse field [must_not]')

New contributor

F Matt is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

match_phrase dosen’t support array as values you need to change this

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{"match_phrase":{"folderIdentifier.identifierValue":['elem1','elem2']}}
</code>
<code>{"match_phrase":{"folderIdentifier.identifierValue":['elem1','elem2']}} </code>
{"match_phrase":{"folderIdentifier.identifierValue":['elem1','elem2']}}

to this

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>"bool":{
"should":[
{"match_phrase":{"folderIdentifier.identifierValue":'elem1'}},
{"match_phrase":{"folderIdentifier.identifierValue":'elem2'}}]}
</code>
<code>"bool":{ "should":[ {"match_phrase":{"folderIdentifier.identifierValue":'elem1'}}, {"match_phrase":{"folderIdentifier.identifierValue":'elem2'}}]} </code>
"bool":{

    "should":[
    {"match_phrase":{"folderIdentifier.identifierValue":'elem1'}},
    {"match_phrase":{"folderIdentifier.identifierValue":'elem2'}}]}

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật