Beispiel #1
0
    def get(self, request, doc_id):
        results = []

        errorMsg = {
            "message":
            "error executing ElasticSearch query; " + "please check the logs"
        }
        errorMsgJSON = json.dumps(errorMsg)

        try:
            queries = XSEQueries(
                XDSConfiguration.objects.first().target_xse_host,
                XDSConfiguration.objects.first().target_xse_index,
                user=request.user)
            response = queries.more_like_this(doc_id=doc_id)
            results = queries.get_results(response)
        except HTTPError as http_err:
            logger.error(http_err)
            return HttpResponseServerError(errorMsgJSON,
                                           content_type="application/json")
        except Exception as err:
            logger.error(err)
            return HttpResponseServerError(errorMsgJSON,
                                           content_type="application/json")
        else:
            logger.info(results)
            return HttpResponse(results, content_type="application/json")
Beispiel #2
0
    def test_more_like_this(self):
        """"Test that calling more_like_this returns whatever response elastic\
              search returns"""
        with patch('elasticsearch_dsl.Search.execute') as es_execute:
            resultVal = {"test": "test"}
            es_execute.return_value = {"test": "test"}
            query = XSEQueries('test', 'test')

            result = query.more_like_this(1)
            self.assertEqual(result, resultVal)