# SearchParseException\[No mapping found for \[username.exact\]

**URL:** <https://forum.dimagi.com/t/searchparseexception-no-mapping-found-for-username-exact/7418>\
**Category:** Developers\
**Created:** [April 24, 2020, 1:13pm UTC](https://forum.dimagi.com/t/searchparseexception-no-mapping-found-for-username-exact/7418 "2020-04-24T13:13:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![demis08](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/demis08/32/1234_2.png) [@demis08](https://forum.dimagi.com/u/demis08)\
**Post date:** [April 24, 2020, 1:13pm UTC](https://forum.dimagi.com/t/searchparseexception-no-mapping-found-for-username-exact/7418/1 "2020-04-24T13:13:48Z")

</div>

Hi,

am getting the following error while navigating to web user list on dashboard.

on elasticsearch log the following error displayed

`tail -f /opt/data/elasticsearch-2.4.6/logs/covid-es.log`

Caused by: SearchParseException[failed to parse search source [{"query": {"filtered": {"filter": {"and": [{"or": [{"term": {"domain.exact": "$  
ovid19"}}, {"term": {"domain\_memberships.domain.exact": "covid19"}}]}, {"term": {"doc\_type": "WebUser"}}, {"term": {"base\_doc": "couchuser"}},  
{"term": {"is\_active": true}}]}, "query": {"match\_all": {}}}}, "sort": [{"username.exact": {"order": "asc"}}], "from": 0, "size": 5}]]; neste  
d: SearchParseException[No mapping found for [username.exact] in order to sort on];  
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:873)  
at org.elasticsearch.search.SearchService.createContext(SearchService.java:667)  
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:633)  
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:377)  
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportActi  
on.java:368)  
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAct$  
on.java:365)  
at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33)  
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:77)  
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:378)  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)  
at java.lang.Thread.run(Thread.java:748)  
Caused by: SearchParseException[No mapping found for [username.exact] in order to sort on]  
at org.elasticsearch.search.sort.SortParseElement.addSortField(SortParseElement.java:213)  
at org.elasticsearch.search.sort.SortParseElement.addCompoundSortField(SortParseElement.java:187)  
at org.elasticsearch.search.sort.SortParseElement.parse(SortParseElement.java:85)  
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:856)  
... 12 more

and this is the `django.log`

`tail -f /home/cchq/www/echis/log/django.log `

return view\_func(request, domain, \*args, \*\*kwargs)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/django/views/decorators/http.py", line 40, in inner  
return func(request, \*args, \*\*kwargs)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/apps/users/views/ **init**.py", line 579, in paginate\_web\_users  
.start(skip).size(limit).run()  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/apps/es/es\_query.py", line 220, in run  
es\_instance\_alias=self.es\_instance\_alias,  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/elastic.py", line 216, in run\_query  
raise ESError(e)  
corehq.elastic.ESError: TransportError(400, 'search\_phase\_execution\_exception')

`while all elasticsearch indices showing healthy`

`curl -XGET 172.31.85.158:9200/_cat/indices`

green open smslogs\_2020-01-28 5 1 0 0 1.5kb 795b  
green open xforms\_2016-07-07 5 1 0 0 1.5kb 795b  
green open case\_search\_2018-05-29 5 1 0 0 1.5kb 795b  
green open hqgroups\_2017-05-29 5 1 0 0 1.5kb 795b  
green open report\_cases\_czei39du507m9mmpqk3y01x72a3ux4p0 5 1 0 0 1.5kb 795b  
green open hqapps\_2020-02-26 5 1 61 180 5.4mb 2.7mb  
green open hqusers\_2017-09-07 2 1 5 1 153.5kb 76.7kb  
green open hqdomains\_2020-02-10 5 1 1 1 59kb 29.5kb  
green open report\_xforms\_20160824\_1708 5 1 0 0 1.5kb 795b  
green open hqcases\_2016-03-04 5 1 0 0 1.5kb 795b

---

<div class="post-metadata">

**Author:** ![Ethan\_Soergel](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ethan_soergel/32/543_2.png) [@Ethan\_Soergel](https://forum.dimagi.com/u/Ethan_Soergel)\
**Post date:** [April 24, 2020, 2:04pm UTC](https://forum.dimagi.com/t/searchparseexception-no-mapping-found-for-username-exact/7418/2 "2020-04-24T14:04:48Z")

</div>

Is this a new environment? It looks like the mapping isn't registered in that index. I'd try resetting it:

```auto
./manage.py update_es_mapping hqusers

```

---

<div class="post-metadata">

**Author:** ![demis08](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/demis08/32/1234_2.png) [@demis08](https://forum.dimagi.com/u/demis08)\
**Post date:** [April 24, 2020, 2:22pm UTC](https://forum.dimagi.com/t/searchparseexception-no-mapping-found-for-username-exact/7418/3 "2020-04-24T14:22:35Z")

</div>

yes, it's new environement

the command `./manage.py update_es_mapping hqusers` brings an error

Confirm that you want to update the mapping for 'hqusers\_2017-09-07' [y/n]y  
Traceback (most recent call last):  
File "manage.py", line 195, in   
main()  
File "manage.py", line 41, in main  
execute\_from\_command\_line(sys.argv)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/django/core/management/ **init**.py", line 36  
4, in execute\_from\_command\_line  
utility.execute()  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/django/core/management/ **init**.py", line 35  
6, in execute  
self.fetch\_command(subcommand).run\_from\_argv(self.argv)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/django/core/management/base.py", line 283, i  
n run\_from\_argv  
self.execute(\*args, \*\*cmd\_options)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/django/core/management/base.py", line 330, i  
n execute [8/1920] output = self.handle(\*args, \*\*options)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/ex-submodules/pillowtop/management/commands/update\_es\_mapping.py", line 38, in h  
andle  
mapping\_res = es.indices.put\_mapping(index\_info.type, {index\_info.type: mapping}, index=index\_info.index)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 69, in  
\_wrapped  
return func(\*args, params=params, \*\*kwargs)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/client/indices.py", line 289,  
in put\_mapping  
'\_mapping', doc\_type), params=params, body=body)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/transport.py", line 307, in pe  
rform\_request  
status, headers, data = connection.perform\_request(method, url, params, body, ignore=ignore, timeout=timeout)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/connection/http\_urllib3.py", l  
ine 93, in perform\_request  
self.\_raise\_error(response.status, raw\_data)  
File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 105,  
in \_raise\_error  
raise HTTP\_EXCEPTIONS.get(status\_code, TransportError)(status\_code, error\_message, additional\_info)  
elasticsearch.exceptions.RequestError: TransportError(400, 'illegal\_argument\_exception')

---

<div class="post-metadata">

**Author:** ![Ethan\_Soergel](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ethan_soergel/32/543_2.png) [@Ethan\_Soergel](https://forum.dimagi.com/u/Ethan_Soergel)\
**Post date:** [April 24, 2020, 5:32pm UTC](https://forum.dimagi.com/t/searchparseexception-no-mapping-found-for-username-exact/7418/4 "2020-04-24T17:32:28Z")

</div>

Elasticsearch is returning a 400 error - what version of elasticsearch is running? If it's 1.x, you'll need to upgrade to 2.x as described in [this changelog entry](https://dimagi.github.io/commcare-cloud/changelog/0032-upgrade-to-elasticsearch-2.4.6.html). If you're already on 2.4.6, could you try to figure out why Elasticsearch considers that a bad request? I was able to successfully run that command, so I suspect it's a version problem.

---

<div class="post-metadata">

**Author:** ![demis08](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/demis08/32/1234_2.png) [@demis08](https://forum.dimagi.com/u/demis08)\
**Post date:** [April 24, 2020, 6:05pm UTC](https://forum.dimagi.com/t/searchparseexception-no-mapping-found-for-username-exact/7418/5 "2020-04-24T18:05:39Z")

</div>

Actually, am using elasticsearch 2.4.6 as shown below.

(ansible) ansible@covid0:~/.commcare-cloud/repo$ curl -XGET 172.31.85.158:9200  
{  
"name" : "es0",  
"cluster\_name" : "covid-es",  
"cluster\_uuid" : "KuvZCzbORayP0KakZgjG1Q",  
"version" : {  
"number" : "2.4.6",  
"build\_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",  
"build\_timestamp" : "2017-07-18T12:17:44Z",  
"build\_snapshot" : false,  
"lucene\_version" : "5.5.4"  
},  
"tagline" : "You Know, for Search"  
}

The same version of ES is working without issue on locally deployed server.

---

<div class="post-metadata">

**Author:** ![demis08](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/demis08/32/1234_2.png) [@demis08](https://forum.dimagi.com/u/demis08)\
**Post date:** [April 24, 2020, 8:00pm UTC](https://forum.dimagi.com/t/searchparseexception-no-mapping-found-for-username-exact/7418/6 "2020-04-24T20:00:52Z")

</div>

Hi Ethan,

issue has been solved. these are the steps i walk through.

1. i re-install elastic-search cluster.
2. run `chq <env> django-manage ptop_preindex`
3. the above command throws the following error

> Traceback (most recent call last):  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/apps/hqcase/management/commands/ptop\_preindex.py", line 120, in handle  
> job.get()  
> File "src/gevent/greenlet.py", line 683, in gevent.\_greenlet.Greenlet.get  
> File "src/gevent/greenlet.py", line 317, in gevent.\_greenlet.Greenlet.\_raise\_exception  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/gevent/\_compat.py", line 47, in reraise  
> raise value.with\_traceback(tb)  
> File "src/gevent/greenlet.py", line 766, in gevent.\_greenlet.Greenlet.run  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/apps/hqcase/management/commands/ptop\_preindex.py", line 52, in do\_reindex  
> FACTORIES\_BY\_SLUGreindex\_command.build().reindex()  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/ex-submodules/pillowtop/reindexer/reindexer.py", line 265, in reindex  
> \_prepare\_index\_for\_reindex([self.es](http://self.es/), self.index\_info)  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/ex-submodules/pillowtop/reindexer/reindexer.py", line 153, in \_prepare\_index\_for\_reindex  
> set\_index\_reindex\_settings(es, index\_info.index)  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/ex-submodules/pillowtop/es\_utils.py", line 119, in set\_index\_reindex\_settings  
> return ElasticsearchInterface(es).update\_index\_settings(index, INDEX\_REINDEX\_SETTINGS)  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/corehq/util/es/interface.py", line 20, in update\_index\_settings  
> return self.es.indices.put\_settings(settings\_dict, index=index)  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 69, in \_wrapped  
> return func(\*args, params=params, \*\*kwargs)  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/client/indices.py", line 620, in put\_settings  
> '\_settings'), params=params, body=body)  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/transport.py", line 307, in perform\_request  
> status, headers, data = connection.perform\_request(method, url, params, body, ignore=ignore, timeout=timeout)  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/connection/http\_urllib3.py", line 93, in perform\_request  
> self.\_raise\_error(response.status, raw\_data)  
> File "/home/cchq/www/echis/releases/2020-04-24\_06.56/python\_env-3.6/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 105, in \_raise\_error  
> raise HTTP\_EXCEPTIONS.get(status\_code, TransportError)(status\_code, error\_message, additional\_info)  
> elasticsearch.exceptions.RequestError: TransportError(400, 'illegal\_argument\_exception')

1. Then i run `cchq <env> django-manage run_ptop --all`  
at this cmd execution, elasticsearch is updating mapping for `app index`

> [2020-04-24 19:37:08,799][INFO][cluster.metadata] [es1] [hqapps\_2020-02-26] update\_mapping [app]

it works for the time being, please give me a comment if i need to see it further.
