2011-12-27 53 views
6

我正在關閉pyes使用示例hereElasticSearch通過pyes分頁。偏移忽略

我索引測試指標有四個文件,然後再使用不同的偏移查詢。 開始參數不會改變我的偏移量,不管它的值如何,我都會得到相同的結果。這是爲什麼發生?

from pyes import * 
conn = ES(["localhost:9200"]) 
try: 
    conn.delete_index('test-index') 
except: 
    pass 

conn.create_index('test-index') 

mapping = {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'}} 

conn.put_mapping("test-type", {'properties':mapping}, ["test-index"]) 

conn.index({"name":"Joe Tester", "uuid":"11111", "position":1}, "test-index", "test-type", 1) 
conn.index({"name":"Bill Baloney", "uuid":"22222", "position":2}, "test-index", "test-type", 2) 
conn.index({"name":"Joe Joseph", "uuid":"33333", "position":3}, "test-index", "test-type", 3) 
conn.index({"name":"Last Joe", "uuid":"44444", "position":4}, "test-index", "test-type", 4) 

conn.refresh(["test-index"]) 

q = TermQuery("name", "joe") 
r0 = conn.search(q, indices = ["test-index"], start=0, size=1) 
r1 = conn.search(q, indices = ["test-index"], start=1, size=1) 
r2 = conn.search(q, indices = ["test-index"], start=2, size=1) 

print('0: {0}'.format(r0['hits']['hits'])) 
print('1: {0}'.format(r1['hits']['hits'])) 
print('2: {0}'.format(r2['hits']['hits'])) 

輸出:

$ python pagination.py 
0: [{u'_score': 0.19178301, u'_type': u'test-type', u'_id': u'4', u'_source': {u'position': 4, u'name': u'Last Joe', u'uuid': u'44444'}, u'_index': u'test-index'}] 
1: [{u'_score': 0.19178301, u'_type': u'test-type', u'_id': u'4', u'_source': {u'position': 4, u'name': u'Last Joe', u'uuid': u'44444'}, u'_index': u'test-index'}] 
2: [{u'_score': 0.19178301, u'_type': u'test-type', u'_id': u'4', u'_source': {u'position': 4, u'name': u'Last Joe', u'uuid': u'44444'}, u'_index': u'test-index'}] 

我pyes版本是0.16.0

回答

4

問題在於如何將請求發送給ES,但我仍不清楚它爲什麼失敗。

而是直接發送查詢ES像我一樣,最初的:

r0 = conn.search(q, indexes = ["test-index"], start=0, size=1) 
r1 = conn.search(q, indexes = ["test-index"], start=1, size=1) 
r2 = conn.search(q, indexes = ["test-index"], start=2, size=1) 

我包裹着我的pyes.query.Search對象查詢:

r0 = conn.search(Search(q, start=0, size=1), indexes = ["test-index"]) 
r1 = conn.search(Search(q, start=1, size=1), indexes = ["test-index"]) 
r2 = conn.search(Search(q, start=2, size=1), indexes = ["test-index"]) 

這工作,看到輸出如下:

0s: [{u'_score': 0.19178301, u'_type': u'test-type', u'_id': u'4', u'_source': {u'position': 4, u'name': u'Last Joe', u'uuid': u'44444'}, u'_index': u'test-index'}] 
1s: [{u'_score': 0.19178301, u'_type': u'test-type', u'_id': u'1', u'_source': {u'position': 1, u'name': u'Joe Tester', u'uuid': u'11111'}, u'_index': u'test-index'}] 
2s: [{u'_score': 0.19178301, u'_type': u'test-type', u'_id': u'3', u'_source': {u'position': 3, u'name': u'Joe Joseph', u'uuid': u'33333'}, u'_index': u'test-index'}] 
+0

我遇到了麻煩,並且在彈性搜索解析搜索時得到了沒有查詢註冊的異常。你使用哪種版本的pyes? –

+0

@Matt Pyes版本0.16.0 –

+0

'索引'參數令人困惑,因爲在Pyes測試用例中使用了'索引'。 '索引'被忽略並且所有索引被搜索。如果它們具有相同的映射,或者只有一個索引很好,如果不是,則會看到一個錯誤。 –