Elastic search version is old 7.9 and Cypress is trying to connect via plugins file using the javascript client. Problem overserved is that the code to fetch the data from required index works all good and logging shows the data fetched and printed on the console when test is executed using the cypress open. But same test fails to fetch the data and just lets the test pass without printing any data on console when test is executed using cypress run.
Code to fetch the data:
const result = await client.search({ index: 'product-v2.0', body: {"query": query}, searchType: "query_then_fetch", trackScores: true, size: 2 })
The query object is as following:
{
"bool": {
"must_not": [
{
"bool": {
"filter": [
{
"exists": {
"field": "gp"
}
}
]
}
}
],
"filter": [
{
"term": {
"webstatus": "1"
}
}
]
}
},
"_source": [
"stockcode"
]
}
When using cypress open -- Following is the part of the trace logging level for the request being fired:
-> POST https://elasticsearch.xxxxxxxxxx.net:443/product-v2.0/_search?search_type=query_then_fetch&track_scores=true&size=2
{
"query": {
"bool": {
"must_not": [
{
"bool": {
"filter": [
{
"exists": {
"field": "gp"
}
}
]
}
}
],
"filter": [
{
"term": {
"webstatus": "1"
}
}
]
}
}
}
That clearly showed that all the search parameters I used are part of the request itself -
POST https://elasticsearch.xxxxxxxxxxxxxx.net:443/product-v2.0/_search?search_type=query_then_fetch&track_scores=true&size=2
My requirement - I need to run it not as ‘cypress open’ - but as ‘cypress run’ process
When I run the same code as cypress run and pass the spec file to be executed - it somehow messes with the query being created and adds and additional ‘query’ to the body of the query instead of placing all the parameters to the request as in case when ‘cypress open’ was used. Following is the part of the trace logging level for the request being fired via cypress run:
starting request {
"method": "POST",
"path": "/product-v2.0/_search",
"body": {
"query": {
"bool": {
"must_not": [
{
"bool": {
"filter": [
{
"exists": {
"field": "gp"
}
}
]
}
}
],
"filter": [
{
"term": {
"webstatus": "1"
}
}
]
}
}
},
"query": {
"search_type": "query_then_fetch",
"track_scores": true,
"size": 2
}
}
This doesn't fetch any data as well as doens't fail the test and doesn't show much in the logging to convey what happened over there. Any help to sort this or is there any where else I should raise this issue ?
I have tried using ES JS client for version 8 also but in that case also same observation is seen. Cypress open works but cypress run doesn't.