How to use the pandasticsearch.errors.DataFrameException function in pandasticsearch

To help you get started, we’ve selected a few pandasticsearch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onesuper / pandasticsearch / pandasticsearch / dataframe.py View on Github external
def _get_mappings(self, json_map, index_name):
        if self._compat >= 7:
            return DataFrame.resolve_mappings(json_map[index_name]["mappings"]["properties"])
        else:
            if self._doc_type is not None:
                return DataFrame.resolve_mappings(json_map[index_name]["mappings"][self._doc_type]["properties"])
            else:
                raise DataFrameException('Please specify doc_type for ES version under 7')
github onesuper / pandasticsearch / pandasticsearch / dataframe.py View on Github external
def _get_cols(self, mapping):
        index = list(mapping.keys())[0]
        cols = self._get_mappings(mapping, index)

        if len(cols) == 0:
            raise DataFrameException('0 columns found in mapping')
        return cols
github onesuper / pandasticsearch / pandasticsearch / dataframe.py View on Github external
:param n:  Number of rows to show.
        :param truncate:  Number of words to be truncated for each column.

        >>> df.filter(df['age'] < 25).select('name').show(3)
        +------+
        | name |
        +------+
        | Alice|
        | Bob  |
        | Leo  |
        +------+
        """
        assert n > 0

        if self._aggregation:
            raise DataFrameException('show() is not allowed for aggregation. use collect() instead')

        query = self._execute()

        if self._projection:
            cols = [col.field_name() for col in self._projection]
        else:
            cols = self.columns

        if cols is None:
            raise _unbound_index_err

        sys.stdout.write(query.result_as_tabular(cols, n, truncate))
        sys.stdout.write('time: {0}ms\n'.format(query.millis_taken))
github onesuper / pandasticsearch / pandasticsearch / dataframe.py View on Github external
|-- regions :  {'index': 'not_analyzed', 'type': 'string'}
        """
        if self._index is None:
            return

        sys.stdout.write('{0}\n'.format(self._index))
        index_name = list(self._mapping.keys())[0]
        if self._compat >= 7:
            json_obj = self._mapping[index_name]["mappings"]["properties"]
            sys.stdout.write(self.resolve_schema(json_obj))
        else:
            if self._doc_type is not None:
                json_obj = self._mapping[index_name]["mappings"][self._doc_type]["properties"]
                sys.stdout.write(self.resolve_schema(json_obj))
            else:
                raise DataFrameException('Please specify mapping for ES version under 7')
github onesuper / pandasticsearch / pandasticsearch / dataframe.py View on Github external
# -*- coding: UTF-8 -*-

from pandasticsearch.client import RestClient
from pandasticsearch.queries import Agg, Select
from pandasticsearch.operators import *
from pandasticsearch.types import Column, Row
from pandasticsearch.errors import DataFrameException

import json
import six
import sys
import copy

_unbound_index_err = DataFrameException('DataFrame is not bound to ES index')

_count_aggregator = MetricAggregator('_index', 'value_count', alias='count').build()


class DataFrame(object):
    """
    A :class:`DataFrame` treats index and documents in Elasticsearch as named columns and rows.

    >>> from pandasticsearch import DataFrame
    >>> df = DataFrame.from_es('http://localhost:9200', index='people')

    Customizing the endpoint of the ElasticSearch:

    >>> from pandasticsearch import DataFrame
    >>> from pandasticsearch.client import RestClient
    >>> df = DataFrame(client=RestClient('http://host:port/v2/_search',), index='people')