ruflin / Elastica

Elastica is a PHP client for elasticsearch
http://elastica.io/
MIT License
2.26k stars 736 forks source link

NullTransport missing the suggest body in the response #1473

Open fubuki opened 6 years ago

fubuki commented 6 years ago

When I use NullTranport.php to test suggest function on elasticsearch 5.6.6 with Elastica 5.3.1, the search method will not return suggest body.

If there are no suggest results in elasticsearch, elasticsearch server will return

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 15,
    "successful": 15,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": 0,
    "hits": []
  },
  "suggest": {
    "suggest": [
      {
        "text": "no result",
        "offset": 0,
        "length": 11,
        "options": []
      }
    ]
  }
}

But NullTranport.php will return

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 0,
    "successful": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}
ruflin commented 6 years ago

The NullTransport is only used for testing and responds with a hardcoded answer: https://github.com/ruflin/Elastica/blob/master/lib/Elastica/Transport/NullTransport.php#L26 We can definitively extend the NullTransport for more tests if needed. Feel free to open a PR.