Advertisement
Guest User

pyes 'fields' test

a guest
Nov 23rd, 2012
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import pyes, time
  2. import traceback
  3.  
  4. ES = pyes.ES('localhost:9200')
  5. mapping = { u'parsedtext': {'boost': 1.0,
  6.                                    'index': 'analyzed',
  7.                                    'store': 'yes',
  8.                                    'type': u'string',
  9.                                    "term_vector": "with_positions_offsets"},
  10.             u'name': {'boost': 1.0,
  11.                      'index': 'analyzed',
  12.                      'store': 'yes',
  13.                      'type': u'string',
  14.                      "term_vector": "with_positions_offsets"},
  15.             u'title': {'boost': 1.0,
  16.                       'index': 'analyzed',
  17.                       'store': 'yes',
  18.                       'type': u'string',
  19.                       "term_vector": "with_positions_offsets"},
  20.             u'pos': {'store': 'yes',
  21.                     'type': u'integer'},
  22.             u'uuid': {'boost': 1.0,
  23.                      'index': 'not_analyzed',
  24.                      'store': 'yes',
  25.                      'type': u'string'}}
  26. try:
  27.     ES.delete_index('oolong')
  28. except:
  29.     traceback.print_exc()
  30. ES.create_index('oolong')
  31. ES.put_mapping('bam', {'properties': mapping, "_source" : { "enabled" : "false" },}, 'oolong')
  32. ES.index({"name": "Joe Tester", "parsedtext": "Joe Testere nice guy", "uuid": "11111", "position": 1},
  33.             'oolong', 'bam', 1)
  34.  
  35. q = pyes.TermQuery("name", "joe")
  36. resultset = ES.search(query=q, indices='oolong', fields=["name"])
  37. ES.refresh()
  38. print resultset.count()
  39. print resultset[0]
  40. time.sleep(3)
  41. ES.delete_index('oolong')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement