Describe the bug
When searching for products using ElasticSearch, we are getting a search_phase_execution_exception. This happens in de query that fetches the FacetValues, the query to actually fetch the products seems to work just fine.
{
"query": {
"bool": {
"filter": [
{"term":{"channelId":1}},
{"term":{"languageCode":"en"}}
]
}
},
"sort":[],
"from":0,
"size":0,
"aggs": {
"facetValue":
{"terms":{"field":"facetValueIds","size":50}}
}
}
To Reproduce
Setup Vendure dev server with the ElasticSearchPlugin, populate, reindex, run a search query that requests the FacetValues:
query {
search (input: {}) {
facetValues {
facetValue {
id
}
}
}
}
Environment (please complete the following information):
Hi, I'm not able to reproduce this on the current master branch.
Is there any more detail you can provide which might help me reproduce? Any special config you are doing on the Elasticsearch plugin?
Or any other pertinent data such as stack trace or graphql response?
Hi Michael
We are running the ElasticSearch docker instance using the following command:
docker run -p 9200:9200 -p 9300:9300 -e \"discovery.type=single-node\" docker.elastic.co/elasticsearch/elasticsearch:7.7.1
In the dev-config file the DefaultSearchPlugin has been replaced with:
ElasticsearchPlugin.init({
host: 'http://localhost',
port: 9200,
}),
The graphql response we are getting is the following:
{
"errors": [
{
"message": "search_phase_execution_exception",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"search",
"facetValues"
]
}
],
"data": null
}
And finally the stack trace from the server:
[run:server] error 03/11/20, 18:36 - [ElasticsearchPlugin] search_phase_execution_exception
[run:server] ResponseError: search_phase_execution_exception
[run:server] at IncomingMessage.<anonymous> (./vendure/node_modules/@elastic/elasticsearch/lib/Transport.js:257:25)
[run:server] at IncomingMessage.emit (events.js:326:22)
[run:server] at endReadableNT (_stream_readable.js:1244:12)
[run:server] at processTicksAndRejections (internal/process/task_queues.js:80:21)
Again, searching works just fine, the error is only there when the facetValues are also queried like in the graphql request from my initial post.
Thank you very much already for taking your time to dig in to this issue!
Thanks for the extra detail. I've managed to reproduce this now in a project. Debugging the error, I root_cause field of the Error is given as:
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [facetValueIds] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
I believe this is because in v0.16.1, a change was made to the way documents are indexed in ES. Deleting the 2 vendure indices and re-starting the server will re-created the indices with the correct field types, and should fix the issue. Please let me know.
Thank you very much Michael, this has indeed resolved the issue for me!
I am new to ELastic search, would somebody please tell me how may I "Delete the 2 vendure indices", Is that something I'd do programmatically using admin-api, or it should be done by running some manual commands on the Elastic search instance?
I am using AWS ElasticSearch.
Deleting an index is something you can do via the Elasticsearch API directly: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html
It is analogous to "dropping a database" in an SQL DB. I'm not familiar with AWS Elasticsearch so I don't know if they have soe dashboard-based way of deleting.
Most helpful comment
Thank you very much Michael, this has indeed resolved the issue for me!