2

I am trying to run functions from an elasticsearch instance through to datatables to display results.

I am only getting 10 to show and no matter the query I get the same 10 all the time. Currently there are 141,000 results in elasticsearch but only able to read 10 in datatables.

<script src="//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.8/js/jquery.dataTables.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.8/js/dataTables.bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.8/js/dataTables.jqueryui.min.js"></script>
<script src="//cdn.datatables.net/responsive/1.0.6/js/dataTables.responsive.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.8/js/dataTables.bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/elasticsearch/10.0.1/elasticsearch.min.js"></script>
<script src="/javascript/jquery.elastic-datatables.js"></script>
<script>
    var client = elasticsearch.Client({
        host: 'localhost:9200'
    });


    $('#orders').dataTable({
        'bProcessing': true,
        'bServerSide': true,
        'columns': [
            { 'sTitle': 'Order Code', 'sName': 'channel_order_code' },
            { 'sTitle': 'Created', 'sName': 'created_at' },
            { 'sTitle': 'Order ID', 'sName': 'po_number' },
            { 'sTitle': 'Tracking', 'sName': 'tracking' },
            { 'sTitle': 'Name', 'sName': 'bill_to_name' },
            { 'sTitle': 'Phone', 'sName': 'customer_phone' },
            { 'sTitle': 'Email', 'sName': 'customer_email' },
            { 'sTitle': 'Group ID', 'sName': 'group_id' },
            { 'sTitle': 'Order Status', 'sName': 'status' },
            { 'sTitle': 'Upload Status', 'sName': 'upload_status' },
            { 'sTitle': 'Subtotal', 'sName': 'subtotal_amount' },
            { 'sTitle': 'Shipping', 'sName': 'channel' },
            { 'sTitle': 'State', 'sName': 'state' }
        ],
        'fnServerData': $.fn.dataTable.elastic_datatables( {
            index: 'orders',
            type:'logs',
            client,
            body: {
                query: {
                    match_all: {

                    }
                }
            }
        } )
</script>

When I go to the url and enter /orders/_search?q=* I get the full results, however, through this I get 10. When I put in _search or search in the 'type' I get nothing, when I remove 'type' I get the same 10.

Any help is appreciated.

This is the package using for jquery.elastic-datatables.js https://github.com/pidupuis/elastic-datatables

1 Answer 1

0

10 is the default number of results returned from Elasitcsearch.

Querying ES directly, you can increase the number of results with size or add an offset with from: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

Please don't forget the default maximum size is 10.000. Please utilize from if you need a bigger data. You can change the maximum size from the index.max_result_window setting though.

Based on the description here: https://github.com/pidupuis/elastic-datatables/ you don't need to mess with size/from in the ES query directly, and can request n results by specifying the aoData.length parameter for DataTables.

You should be able to request the next n by including the aoData.start parameter: https://github.com/pidupuis/elastic-datatables/blob/7bb98580add1c3b58fdf776426606c5fe65a1deb/src/jquery.elastic-datatables.js#L33-L34

Sign up to request clarification or add additional context in comments.

7 Comments

I know I shouldn't however I am still getting just 10 results, the count on the footer of datatables should show the hits from ES, and are showing Showing 1 to 10 of 10 entries. Even when I use a size/from setting manually.
I was able to reproduce this. I'm not seeing the a POST body going to ES as part of the request, which would cause the behavior you described. Are you seeing it on your end?
I am not seeing post going through on my end
Meaning no HTTP request, or no body?
I am getting no POST request, just GET.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.