def __init__(self, graph, index, doc_type=None): """ :param graph: the object graph :param index: the name of an index to use :param doc_type: the doc type to search for; uses the index's doc types if omitted """ self.elasticsearch_client = graph.elasticsearch_client self.index = index # Mapping from ES custom type field to corresponding model class self.doc_types = dict() self.mapping = Mapping(self.mapping_type_name) if doc_type is not None: self.register_doc_type(doc_type)
def _is_allowed_key_field_type(client: Elasticsearch, key_field: str, index: str) -> bool: """Return ``True`` if the given field's mapping in the given index is in our allowed list of ES types compatible with term(s) queries This is mainly to prevent use of ``text`` fields in terms queries, which give bad results because Elasticsearch changes the values of text fields during analysis. """ if key_field == "_id": # Special case. It is a reserved field, without a type, but can effectively be treated as a keyword field return True # Get true index name from alias, if provided an alias response = client.indices.get(index) aliased_index_name = list(response.keys())[0] es_field_type = Mapping().from_es( using=client, index=aliased_index_name).resolve_field(key_field) # This is the allowed types whitelist. More can be added as-needed if compatible with terms(s) queries. if es_field_type and es_field_type.name in ["keyword", "integer"]: return True return False
class Meta(object): mapping = Mapping("wiki_document") mapping.meta("_all", enabled=False)
class Meta(object): mapping = Mapping('wiki_document') mapping.meta('_all', enalbed=False)