RequestError:TransportError(400,u' parsing_exception')

时间:2017-08-01 12:52:31

标签: python django elasticsearch django-haystack

我正在为我的应用程序使用django-haystack和Elasticsearch。我已经加载了所有要求并尝试使用search.html

搜索我的索引

但是每当我尝试使用http://localhost:8000/search处的API检索结果时,我都会收到以下错误,而且我已经搜索了很多关于此但却无法获得任何帮助的信息:

RequestError: TransportError(400, u'parsing_exception')

在views.py中搜索查询

def search(uri, term):
    query = json.dumps({
        "query": {
        "bool": {
        "filter": {"term":"channel"}
            }
        }
    })
    response = request.get(uri, data=query)
    results = json.loads(response.text)
    return results

在models.py中记录模型

class Recordings(models.Model):
    channel = models.ForeignKey(Channel, related_name="recordings")
    date = models.DateTimeField(auto_now_add=True)
    duration = models.DurationField(default=0)
    file_size = models.FloatField(default=0.0)
    file_location = models.CharField(max_length=255)
    proceed = models.BooleanField(default=False)

    class Meta:
        get_latest_by = 'date'
        ordering = ['-date']
        index_together = ["date", "channel"]

    def __str__(self):
        return '{channel} {date}'.format(Channel=self.channel, date=self.date)

search_indexes.py

from haystack import indexes
from matches.models import Recordings

class NoteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    channel = indexes.CharField(model_attr='channel')
    date = indexes.CharField(model_attr='date')
    file_size = indexes.CharField(model_attr='file_size')
    file_location = indexes.CharField(model_attr='file_location')

    def get_model(self):
        return Recordings

search.html

{% block content %}

<h2>Recordings search</h2>

    <form method="get" action="" class="form" role="form">
        {{ form.non_field_errors }}
        <div class="form-group">
                {{ form.as_p }}
        </div>
        <div class="form-group">
            <input type="submit" class="btn btn-primary" value="Search">
        </div>

        {% if query %}
            <h3>Results</h3>
            <div>
            <table>
                <thead>
                    <tr>
                        <th>channel</th>
                        <th>date</th>
                        <th>file_size</th>
                        <th>file_location</th>
                </thead>
                <tbody>
                    {% for result in page.object_list %}
                        <tr>
                            <td>{{ result.channel }}</td>
                            <td>{{ result.date }}</td>
                            <td>{{ result.file_size }}</td>
                            <td>{{ result.file_location }}</td>
                        </tr>
                    {% empty %}
                        <tr>No results found.</tr>
                    {% endfor %}
                </tbody>
            <table>
            </div>
        {% endif %}
    </form>
{% endblock content %}

{% block extrajs %}
<script>
$(document).ready(function() {
    $('#result_table').DataTable({
        "searching": false
    });
} );
</script>
{% endblock %}

recordings_text.txt

{{ object.title }}
{{ object.channel }}
{{ object.date }}
{{ object.file_size }}
{{ object.file_location }}

0 个答案:

没有答案