nextcloud / fulltextsearch_elasticsearch

🔍 Use Elasticsearch to index the content of your Nextcloud
GNU Affero General Public License v3.0
80 stars 29 forks source link

Create ES client with logger NC implementation #294

Closed R0Wi closed 1 year ago

R0Wi commented 1 year ago

Currently if there's a problem with a ES search query, we're not able to debug the query which is sent to the Elasticsearch server since we only see messages like "Searching ES" (without further info). Instead of trying to log the request on our owns, we should make use of the built-in logging capability of the ES client.

This will give us additional log messages like:

{
  "reqId": "k740GWHGI1fs24c9nd88",
  "level": 0,
  "time": "2023-09-04T18:11:56+00:00",
  "remoteAddr": "172.19.0.1",
  "user": "admin",
  "app": "fulltextsearch_elasticsearch",
  "method": "GET",
  "url": "/index.php/apps/fulltextsearch/v1/search?request=%7B%22providers%22%3A%22all%22%2C%22options%22%3A%7B%7D%2C%22search%22%3A%22beleg%22%2C%22page%22%3A1%7D",
  "message": "Headers: {\"Host\":[\"elasticsearch_nc:9200\"],\"Accept\":[\"application\\/vnd.elasticsearch+json; compatible-with=8\"],\"Content-Type\":[\"application\\/vnd.elasticsearch+json; compatible-with=8\"],\"User-Agent\":[\"elasticsearch-php\\/8.8.2 (Linux 5.15.0-82-generic; PHP 8.1.2-1ubuntu2.13)\"],\"x-elastic-client-meta\":[\"es=8.8.2,php=8.1.2,t=8.7.0,a=0,gu=7.7.0\"]}\nBody: {\"query\":{\"bool\":{\"must\":{\"bool\":{\"should\":[{\"match_phrase_prefix\":{\"content\":\"beleg\"}},{\"match_phrase_prefix\":{\"title\":\"beleg\"}},{\"match_phrase_prefix\":{\"share_names.admin\":\"beleg\"}},{\"wildcard\":{\"title\":\"*beleg*\"}},{\"wildcard\":{\"share_names.admin\":\"*beleg*\"}},{\"query_string\":{\"fields\":[\"parts.comments\"],\"query\":\"beleg\"}}]}},\"filter\":[{\"bool\":{\"must\":{\"term\":{\"provider\":\"files\"}}}},{\"bool\":{\"should\":[{\"term\":{\"owner\":\"admin\"}},{\"term\":{\"users\":\"admin\"}},{\"term\":{\"users\":\"__all\"}},{\"term\":{\"groups\":\"admin\"}}]}},{\"bool\":{\"should\":[]}},{\"bool\":{\"must\":[]}},{\"bool\":{\"must\":[]}}]}},\"highlight\":{\"fields\":{\"content\":{},\"parts.comments\":{}},\"pre_tags\":[\"\"],\"post_tags\":[\"\"]}}",
  "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
  "version": "28.0.0.2",
  "data": {
    "app": "fulltextsearch_elasticsearch"
  },
  "id": "64f61e6b5d6b6"
}

This makes is possible to reconstruct the ES query and debug it for example via CURL.

R0Wi commented 1 year ago

/backport to stable26

R0Wi commented 1 year ago

/backport to stable27

github-actions[bot] commented 11 months ago

Hello there, Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!