14

jQuery AJAX 呼び出しを使用して、elasticsearch からデータを正しく要求する方法を理解しようとしています。解析エラーが発生するか、検索しているインデックス内のすべてのドキュメントを取得します。

    $(document).ready(function() {

    var timer = null;
    function dicom_search() {
        var box = $('#s_box').val();

        $.ajax({
            url: 'http://localhost:9200/dicoms/dicoms/_search',
            type: 'POST',
            //contentType: 'application/json; charset=UTF-8',
            crossDomain: true,
            dataType: 'json',
            data: {
                query:{match:{_all:$('#s_box').val()}},
                pretty: true,
                fields: '_id'
            },
            success: function(response) {
                var data = response.hits.hits;
                var doc_ids = [];
                var source = null;
                var content = '';

                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        source = data[i].fields;
                        doc_ids.push(source._id);
                        content = content + ' ' + source._id + '<br />';
                    }

                    $('#res').removeClass('text-error').addClass('text-success').html(content);
                } else {
                    $('#res').removeClass('text-success').addClass('text-error').html('No results found.');
                }


            }
        });
    }

    $('#s_box').live('keyup', function() {

        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(dicom_search, 600);

    });
});

これが私のエラーです:

{
   "error":"SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[GUiivW0TQVSNv2HQyxu8Vw][dicoms][0]: SearchParseException[[dicoms][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@779479bb]; }{[GUiivW0TQVSNv2HQyxu8Vw][dicoms][3]: SearchParseException[[dicoms][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@779479bb]; }{[GUiivW0TQVSNv2HQyxu8Vw][dicoms][1]: SearchParseException[[dicoms][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@779479bb]; }{[GUiivW0TQVSNv2HQyxu8Vw][dicoms][4]: SearchParseException[[dicoms][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@779479bb]; }{[GUiivW0TQVSNv2HQyxu8Vw][dicoms][2]: SearchParseException[[dicoms][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@779479bb]; }]",
   "status":500
}

編集:私はそれを理解しました:

var data = {
            query: {
                match: {
                    _all: $('#s_box').val()
                }
            },
            fields: '_id'
        }; 

$.ajax({
            url: 'http://localhost:9200/dicoms/dicoms/_search',
            type: 'POST',
            //contentType: 'application/json; charset=UTF-8',
            crossDomain: true,
            dataType: 'json',
            data: JSON.stringify(data),
            success: function(response) {
                var data = response.hits.hits;
                var doc_ids = [];
                var source = null;
                var content = '';

                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        source = data[i].fields;
                        doc_ids.push(source._id);
                        content = content + ' ' + source._id + '<br />';
                    }

                    $('#res').removeClass('text-error').addClass('text-success').html(content);
                } else {
                    $('#res').removeClass('text-success').addClass('text-error').html('No results found.');
                }


            },
            error: function(jqXHR, textStatus, errorThrown) {
                var jso = jQuery.parseJSON(jqXHR.responseText);
                error_note('section', 'error', '(' + jqXHR.status + ') ' + errorThrown + ' --<br />' + jso.error);
            }
        });
4

2 に答える 2

1

ここで見ることができます: https://github.com/dadoonet/devoxxfr_demo/blob/gh-pages/index.html#L512

問題の解決に役立つ場合があります。

于 2012-10-30T17:57:41.313 に答える