2011-12-27 32 views
6

Tôi đang làm việc ngoài khơi dụ pyes sử dụng herePhân trang tìm kiếm đàn hồi thông qua pyes. Bù đắp lờ

Tôi đang lập chỉ mục kiểm tra-index với bốn tài liệu và truy vấn sau bằng hiệu số khác nhau. Thông số bắt đầu không thay đổi độ lệch cho tôi, tôi tiếp tục nhận được kết quả tương tự bất kể giá trị của nó. Tại sao chuyện này đang xảy ra?

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'])) 

đầu ra:

$ 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'}] 

phiên bản pyes tôi là 0.16.0

Trả lời

4

Vấn đề là cách yêu cầu được gửi đến ES, mặc dù tôi vẫn chưa rõ lý do tại sao nó không thành công.

Thay vì gửi các truy vấn trực tiếp đến ES như tôi đã làm ban đầu:

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) 

tôi quấn truy vấn của tôi trong một đối tượng 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"]) 

Đó làm việc, thấy đầu ra bên dưới:

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

Tôi đang gặp vấn đề với điều này và nhận được không có truy vấn đăng ký ngoại lệ khi tìm kiếm đàn hồi phân tích cú pháp tìm kiếm. Phiên bản của pyes nơi bạn sử dụng? –

+0

@Matt pyes phiên bản 0.16.0 –

+0

param 'chỉ số' là khó hiểu, vì 'chỉ số' được sử dụng trong các trường hợp thử nghiệm pyes. 'chỉ số' bị bỏ qua và tất cả các chỉ mục được tìm kiếm. Nếu họ có cùng một ánh xạ hoặc bạn chỉ có một chỉ mục tốt, nếu không, bạn sẽ thấy một lỗi. –

2

Đảm bảo sử dụng của bạn một loại tìm kiếm của Query then Fetch.

+0

Vâng, rất dễ trộn 'QUERY_AND_FETCH' và' QUERY_THEN_FETCH'. – yatskevich

Các vấn đề liên quan