Help With Elasticsearch DSL MultiMatch Not Working with Searching Through Text and Integer Doc Types? Transport Error 400

Hey everyone,

I'm having trouble getting the elasticsearch DSL to search through text and integer doc types. If I only do the fields with text() or integer(), there is no problem, but when I try to get elasticsearch to search through both types, I have an issue.

Multimatch code:

   elastic_search_query = ProfileDocument.search().query("multi_match",
       query=query,
       fields=[
               'name',
               'city',
               'state',
               'country',
               'job_title',
               'company',
               'id'
           ])

class ProfileDocument(DocType):
name = Text()
city = Text()
state = Text()
country = Text()
job_title = Text()
company = Text()
id = Integer()

ID is the only one that is integer(), the other fields are all text(). If I removed ID, it works fine.

I get this error:
TransportError(400, 'search_phase_execution_exception', 'failed to create query: {\n "multi_match" : {\n "query" : "asdf",\n "fields" : [\n "city^1.0",\n "company^1.0",\n "country^1.0",\n "id^1.0",\n "job_title^1.0",\n "name^1.0",\n "state^1.0"\n ],\n "type" : "best_fields",\n "operator" : "OR",\n "slop" : 0,\n "prefix_length" : 0,\n "max_expansions" : 50,\n "lenient" : false,\n "zero_terms_query" : "NONE",\n "boost" : 1.0\n }\n}')

I also tried it with MultiSearch:

    client = Elasticsearch()
    ms = MultiSearch(using=client, index='profile')

    ms = ms.add(Search().filter('term', id=query))
    ms = ms.add(Search().query('match', name=query))
    ms = ms.add(Search().query('match', city=query))
    ms = ms.add(Search().query('match', state=query))

    elastic_search_query = ms.execute()

    print(elastic_search_query)

This also pulls a TransportError when ID is included, but not when the other types are included.

I've been searching for hours on this issue and reviewed tons of stackoverflow things and the elasticsearch dsl video here, but couldn't find the answer anywhere: https://www.youtube.com/watch?v=hE359wuHyhs&t=191s

I think it should make sense what I'm doing, but I'm not entirely sure. Can anyone provide insight or help?

can you provide the full HTTP request and the full stack trace in the elasticsearch logs?

Stacktrace:

Internal Server Error: /jeff-chen-11648/
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/jeffchen/PycharmProjects/jeffchenseo/jeffchenseo/src/votes/views.py", line 70, in index
for each_hit in elastic_search_query:
File "/usr/local/lib/python3.6/site-packages/elasticsearch_dsl/search.py", line 252, in iter
return iter(self.execute())
File "/usr/local/lib/python3.6/site-packages/elasticsearch_dsl/search.py", line 606, in execute
**self._params
File "/usr/local/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 73, in _wrapped
return func(*args, params=params, **kwargs)
File "/usr/local/lib/python3.6/site-packages/elasticsearch/client/init.py", line 623, in search
doc_type, '_search'), params=params, body=body)
File "/usr/local/lib/python3.6/site-packages/elasticsearch/transport.py", line 312, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/usr/local/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 128, in perform_request
self._raise_error(response.status, raw_data)
File "/usr/local/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, 'search_phase_execution_exception', 'failed to create query: {\n "multi_match" : {\n "query" : "asdf",\n "fields" : [\n "city^1.0",\n "company^1.0",\n "country^1.0",\n "id^1.0",\n "job_title^1.0",\n "name^1.0",\n "state^1.0"\n ],\n "type" : "best_fields",\n "operator" : "OR",\n "slop" : 0,\n "prefix_length" : 0,\n "max_expansions" : 50,\n "lenient" : false,\n "zero_terms_query" : "NONE",\n "boost" : 1.0\n }\n}')

Http request:

Apple_PubSub_Socket_Render
'/private/tmp/com.apple.launchd.vqyDBLLUcq/Render'
BOLD
'\x1b[1m'
COLORFGBG
'12;8'
COMMAND_MODE
'unix2003'
CONTENT_LENGTH
''
CONTENT_TYPE
'text/plain'
CSRF_COOKIE
'x7zsGtPH9K6HO5Td85w0ihNNGj5UbpHcTIqg6rm6Se3Q0K0OADOXgsrhOtZdZMCq'
DJANGO_SETTINGS_MODULE
'jeffchenseo.settings'
GATEWAY_INTERFACE
'CGI/1.1'
GEM_HOME
'/Users/jeffchen/.rvm/gems/ruby-2.4.0'
GEM_PATH
'/Users/jeffchen/.rvm/gems/ruby-2.4.0:/Users/jeffchen/.rvm/gems/ruby-2.4.0@global'
GREEN
'\x1b[38;5;64m'
HOME
'/Users/jeffchen'
HTTP_ACCEPT
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8'
HTTP_ACCEPT_ENCODING
'gzip, deflate, br'
HTTP_ACCEPT_LANGUAGE
'en-US,en;q=0.8'
HTTP_CACHE_CONTROL
'no-cache'
HTTP_CONNECTION
'keep-alive'
HTTP_COOKIE
('djdt=hide; sessionid=kc6zgc2bj1vh6s1a0q5p2z7acxy2qcjc; '
'csrftoken=x7zsGtPH9K6HO5Td85w0ihNNGj5UbpHcTIqg6rm6Se3Q0K0OADOXgsrhOtZdZMCq; '
'_ga=GA1.1.1653284646.1507506355; _gid=GA1.1.718168838.1508558352; _gat=1; '
'__atuvc=31%7C42%2C109%7C43; __atuvs=59eead86d81fa830000')
HTTP_HOST
'127.0.0.1:8000'
HTTP_PRAGMA
'no-cache'
HTTP_REFERER
'http://127.0.0.1:8000/jeff-chen-11648/'
HTTP_UPGRADE_INSECURE_REQUESTS
'1'
HTTP_USER_AGENT
('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, '
'like Gecko) Chrome/61.0.3163.100 Safari/537.36')
IRBRC
'/Users/jeffchen/.rvm/rubies/ruby-2.4.0/.irbrc'
ITERM_PROFILE
'Jeff'
ITERM_SESSION_ID
'w0t0p0:A9F167CF-61B6-4F36-9B22-97FD86E90A95'
LANG
'en_US.UTF-8'
LOGNAME
'jeffchen'
LS_COLORS
'no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:.tar=01;31:.tgz=01;31:.arj=01;31:.taz=01;31:.lzh=01;31:.zip=01;31:.z=01;31:.Z=01;31:.gz=01;31:.bz2=01;31:.deb=01;31:.rpm=01;31:.jar=01;31:.jpg=01;35:.jpeg=01;35:.gif=01;35:.bmp=01;35:.pbm=01;35:.pgm=01;35:.ppm=01;35:.tga=01;35:.xbm=01;35:.xpm=01;35:.tif=01;35:.tiff=01;35:.png=01;35:.mov=01;35:.mpg=01;35:.mpeg=01;35:.avi=01;35:.fli=01;35:.gl=01;35:.dl=01;35:.xcf=01;35:.xwd=01;35:.ogg=01;35:.mp3=01;35:.wav=01;35:'
MAGENTA
'\x1b[38;5;125m'
MY_RUBY_HOME
'/Users/jeffchen/.rvm/rubies/ruby-2.4.0'
OLDPWD
'/Users/jeffchen/PycharmProjects/jeffchenseo/jeffchenseo'
ORANGE
'\x1b[38;5;166m'
PATH
'/Users/jeffchen/PycharmProjects/jeffchenseo/jeffchenseo_env/bin:/Users/jeffchen/.rvm/gems/ruby-2.4.0/bin:/Users/jeffchen/.rvm/gems/ruby-2.4.0@global/bin:/Users/jeffchen/.rvm/rubies/ruby-2.4.0/bin:/Users/jeffchen/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Users/jeffchen/.rvm/bin'
PATH_INFO
'/jeff-chen-11648/'
PS1
('(jeffchenseo_env) \[\x1b[1m\x1b[38;5;125m\]\u \[\x1b[38;5;244m\]at '
'\[\x1b[38;5;166m\]\h \[\x1b[38;5;244m\]in '
'\[\x1b[38;5;64m\]\w\[\x1b[38;5;244m\]$([[ -n $(git branch 2> /dev/null) '
']] && echo " on '
'")\[\x1b[38;5;61m\]$(parse_git_branch)\[\x1b[38;5;244m\]\n$ '
'\[\x1b(B\x1b[m\]')
PS2
'\[\x1b[38;5;166m\]→ \[\x1b(B\x1b[m\]'
PURPLE
'\x1b[38;5;61m'
PWD
'/Users/jeffchen/PycharmProjects/jeffchenseo/jeffchenseo/src'
QUERY_STRING
'q=asdf'
REMOTE_ADDR
'127.0.0.1'
REMOTE_HOST
''
REQUEST_METHOD
'GET'
RESET
'\x1b(B\x1b[m'
RUBY_VERSION
'ruby-2.4.0'
RUN_MAIN
'true'
SCRIPT_NAME
''
SECURITYSESSIONID
'186a8'
SERVER_NAME
'1.0.0.127.in-addr.arpa'
SERVER_PORT
'8000'
SERVER_PROTOCOL
'HTTP/1.1'
SERVER_SOFTWARE
'WSGIServer/0.2'
SHELL
'/bin/bash'
SHLVL
'1'
SSH_AUTH_SOCK
'/private/tmp/com.apple.launchd.D1eAxZZGAx/Listeners'
TERM
'xterm-256color'
TERM_PROGRAM
'iTerm.app'
TERM_PROGRAM_VERSION
'3.0.15'
TERM_SESSION_ID
'w0t0p0:A9F167CF-61B6-4F36-9B22-97FD86E90A95'
TMPDIR
'/var/folders/t5/v0wqfn8s1qx79j05tzv117d00000gn/T/'
TZ
'US/Pacific'
USER
'jeffchen'
VIRTUAL_ENV
'/Users/jeffchen/PycharmProjects/jeffchenseo/jeffchenseo_env'
WHITE
'\x1b[38;5;244m'
XPC_FLAGS
'0x0'
XPC_SERVICE_NAME
'0'
_
'/usr/local/bin/python3'
__CF_USER_TEXT_ENCODING
'0x1F5:0:0'
PYVENV_LAUNCHER
'/usr/local/Cellar/python3/3.6.2/bin/python3.6'
_system_arch
'x86_64'
_system_name
'OSX'
_system_type
'Darwin'
_system_version
'10.12'
rvm_bin_path
'/Users/jeffchen/.rvm/bin'
rvm_path
'/Users/jeffchen/.rvm'
rvm_prefix
'/Users/jeffchen'
rvm_version
'1.29.1 (latest)'
wsgi.errors
<_io.TextIOWrapper name='' mode='w' encoding='UTF-8'>
wsgi.file_wrapper
''
wsgi.input
<_io.BufferedReader name=7>
wsgi.multiprocess
False
wsgi.multithread
True
wsgi.run_once
False
wsgi.url_scheme
'http'
wsgi.version
(1, 0)

Let me know if this works / if this is what you were looking for! The http request seems to be not well formatted, I just grabbed it from the django request info

sorry, this is not what I was looking for, you dumped the environment and a stack trace from your application. I was more interested in the elasticsearch side of exceptions and the full request/response from your application.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.