Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyes, time
- import traceback
- ES = pyes.ES('localhost:9200')
- mapping = { 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'}}
- try:
- ES.delete_index('oolong')
- except:
- traceback.print_exc()
- ES.create_index('oolong')
- ES.put_mapping('bam', {'properties': mapping, "_source" : { "enabled" : "false" },}, 'oolong')
- ES.index({"name": "Joe Tester", "parsedtext": "Joe Testere nice guy", "uuid": "11111", "position": 1},
- 'oolong', 'bam', 1)
- q = pyes.TermQuery("name", "joe")
- resultset = ES.search(query=q, indices='oolong', fields=["name"])
- ES.refresh()
- print resultset.count()
- print resultset[0]
- time.sleep(3)
- ES.delete_index('oolong')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement