Example #1
0
File: tests.py Project: CGenie/pyes
    def init_default_index(self):
        settings = SettingsBuilder({'index.number_of_replicas': 0,
                                     "index.number_of_shards": 1})
        from pyes.mappings import DocumentObjectField
        from pyes.mappings import IntegerField
        from pyes.mappings import NestedObject
        from pyes.mappings import StringField, DateField

        docmapping = DocumentObjectField(name=self.document_type)
        docmapping.add_property(
            StringField(name="parsedtext", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(
            StringField(name="name", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(
            StringField(name="title", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(IntegerField(name="position", store=True))
        docmapping.add_property(DateField(name="date", store=True))
        docmapping.add_property(StringField(name="uuid", store=True, index="not_analyzed"))
        nested_object = NestedObject(name="nested")
        nested_object.add_property(StringField(name="name", store=True))
        nested_object.add_property(StringField(name="value", store=True))
        nested_object.add_property(IntegerField(name="num", store=True))
        docmapping.add_property(nested_object)
        settings.add_mapping(docmapping)

        self.conn.ensure_index(self.index_name, settings)
def create_and_add_mapping(connection, index_name, type_name):
    from pyes.mappings import DocumentObjectField
    from pyes.mappings import IntegerField
    from pyes.mappings import NestedObject
    from pyes.mappings import StringField, DateField

    from pyes.helpers import SettingsBuilder

    settings = SettingsBuilder()
    docmapping = DocumentObjectField(name=type_name)
    docmapping.add_property(
        StringField(name="parsedtext", store=True, term_vector="with_positions_offsets", index="analyzed"))
    docmapping.add_property(
        StringField(name="name", store=True, term_vector="with_positions_offsets", index="analyzed"))
    docmapping.add_property(
        StringField(name="title", store=True, term_vector="with_positions_offsets", index="analyzed"))
    docmapping.add_property(IntegerField(name="position", store=True))
    docmapping.add_property(DateField(name="date", store=True))
    docmapping.add_property(StringField(name="uuid", store=True, index="not_analyzed"))
    nested_object = NestedObject(name="nested")
    nested_object.add_property(StringField(name="name", store=True))
    nested_object.add_property(StringField(name="value", store=True))
    nested_object.add_property(IntegerField(name="num", store=True))
    docmapping.add_property(nested_object)
    settings.add_mapping(docmapping)

    connection.ensure_index(index_name, settings)
    def init_default_index(self):
        from pyes.helpers import SettingsBuilder
        settings = SettingsBuilder()
        from pyes.mappings import DocumentObjectField
        from pyes.mappings import IntegerField
        from pyes.mappings import NestedObject
        from pyes.mappings import StringField, DateField, BooleanField, GeoPointField, FloatField

        docmapping = DocumentObjectField(name=self.document_type)
        docmapping.add_property(
            StringField(name="description", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(
            StringField(name="name", store=True, term_vector="with_positions_offsets", index="analyzed"))
        docmapping.add_property(StringField(name="tag", store=True, index="not_analyzed"))
        docmapping.add_property(IntegerField(name="age", store=True))
        docmapping.add_property(FloatField(name="price"))
        docmapping.add_property(DateField(name="date", store=True))
        docmapping.add_property(BooleanField(name="in_stock", store=True, index="not_analyzed"))
        docmapping.add_property(GeoPointField(name="position"))
        nested_object = NestedObject(name="metadata")
        nested_object.add_property(StringField(name="name", store=True))
        nested_object.add_property(StringField(name="value", store=True))
        nested_object.add_property(IntegerField(name="num", store=True))
        docmapping.add_property(nested_object)
        settings.add_mapping(docmapping)

        self.conn.ensure_index(self.index_name, settings)
Example #4
0
    def init_default_index(self):
        settings = SettingsBuilder()
        settings.add_mapping({self.document_type:{'properties':
                { u'parsedtext': {'boost': 1.0,
                                 'index': 'analyzed',
                                 'store': 'yes',
                                 'type': u'string',
                                 "term_vector" : "with_positions_offsets"},
                         u'name': {'boost': 1.0,
                                    'index': 'analyzed',
                                    'store': 'yes',
                                    'type': u'string',
                                    "term_vector" : "with_positions_offsets"},
                         u'title': {'boost': 1.0,
                                    'index': 'analyzed',
                                    'store': 'yes',
                                    'type': u'string',
                                    "term_vector" : "with_positions_offsets"},
                         u'pos': {'store': 'yes',
                                    'type': u'integer'},
                         u'uuid': {'boost': 1.0,
                                   'index': 'not_analyzed',
                                   'store': 'yes',
                                   'type': u'string'}}
                          }}, name=self.document_type)

        self.conn.create_index(self.index_name, settings)