jurismarches / luqum

A lucene query parser generating ElasticSearch queries and more !
Other
187 stars 42 forks source link

Which Elasticsearch version(s) do you support? #27

Closed jlarkin-auro closed 6 years ago

jlarkin-auro commented 6 years ago

Hello, I am having a problem executing a simple query.

I am running Elasticsearch 6.2.2 locally. From a clean installed base, I do

POST /accounts/person/ 
{
    "name" : "John",
    "lastname" : "Doe",
    "job_description" : "Systems administrator and Linux specialist"
}

I can then run:

GET /accounts/_search?q=name:john

which returns a proper result. I cannot reproduce this result with luqum however. I am trying:

from elasticsearch import Elasticsearch
client = Elasticsearch(host='localhost', port=9200)
client.info()

{'name': 'jQqh6TD',
 'cluster_name': 'elasticsearch',
 'cluster_uuid': 'vMnMGP4XRYC6CAJN7lOzyw',
 'version': {'number': '6.2.2',
  'build_hash': '10b1edd',
  'build_date': '2018-02-16T19:01:30.685723Z',
  'build_snapshot': False,
  'lucene_version': '7.2.1',
  'minimum_wire_compatibility_version': '5.6.0',
  'minimum_index_compatibility_version': '5.0.0'},
 'tagline': 'You Know, for Search'}
schema = client.indices.get_mapping(index='accounts')
schema

{'accounts': {'mappings': {'person': {'properties': {'address': {'properties': {'city': {'type': 'text',
        'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}},
       'street': {'type': 'text',
        'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}}}},
     'height': {'type': 'long'},
     'job_description': {'type': 'text',
      'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}},
     'lastname': {'type': 'text',
      'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}},
     'name': {'type': 'text',
      'fields': {'keyword': {'type': 'keyword', 'ignore_above': 256}}}}}}}}
from luqum.parser import parser
tree = parser.parse('name:john')
query = es_builder(tree)
query

{'match': {'name': {'query': 'john', 'zero_terms_query': 'none'}}}
response = client.search(
    index='accounts',
    body=query
)

This search returns the following stack trace:

GET http://localhost:9200/accounts/_search [status:400 request:0.002s]
---------------------------------------------------------------------------
RequestError                              Traceback (most recent call last)
<ipython-input-187-e42ebfa4fba0> in <module>()
      1 response = client.search(
      2     index='accounts',
----> 3     body=query
      4 )

/anaconda3/lib/python3.6/site-packages/elasticsearch/client/utils.py in _wrapped(*args, **kwargs)
     74                 if p in kwargs:
     75                     params[p] = kwargs.pop(p)
---> 76             return func(*args, params=params, **kwargs)
     77         return _wrapped
     78     return _wrapper

/anaconda3/lib/python3.6/site-packages/elasticsearch/client/__init__.py in search(self, index, doc_type, body, params)
    653             index = '_all'
    654         return self.transport.perform_request('GET', _make_path(index,
--> 655             doc_type, '_search'), params=params, body=body)
    656 
    657     @query_params('_source', '_source_exclude', '_source_include',

/anaconda3/lib/python3.6/site-packages/elasticsearch/transport.py in perform_request(self, method, url, headers, params, body)
    316                 delay = 2**attempt - 1
    317                 time.sleep(delay)
--> 318                 status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
    319 
    320             except TransportError as e:

/anaconda3/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py in perform_request(self, method, url, params, body, timeout, ignore, headers)
    183         if not (200 <= response.status < 300) and response.status not in ignore:
    184             self.log_request_fail(method, full_url, url, body, duration, response.status, raw_data)
--> 185             self._raise_error(response.status, raw_data)
    186 
    187         self.log_request_success(method, full_url, url, body, response.status,

/anaconda3/lib/python3.6/site-packages/elasticsearch/connection/base.py in _raise_error(self, status_code, raw_data)
    123             logger.warning('Undecodable raw error response from server: %s', err)
    124 
--> 125         raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
    126 
    127 

RequestError: TransportError(400, 'parsing_exception', 'Unknown key for a START_OBJECT in [match].')

Please advise on this. Perhaps I am missing something simple! Thank you very much.

alexgarel commented 6 years ago

Hello @jlarkin-auro, can you try

response = client.search(
    index='accounts',
    body={"query": query},
)
alexgarel commented 6 years ago

BTW, we do not know precisely which ES version we support right now ! We would have to do integration test for that (see #22)

alexgarel commented 6 years ago

hi @jlarkin-auro I would happy to know if my advice helped you (in this case I will rename ticket and close it).