8

जब मैं डेटासंग्रह तारीख मैं निम्नलिखित त्रुटि मिलती द्वारा आदेश दिया पर एक प्रश्न चलाने का प्रयास:GAE डेटास्टोर से पूछताछ करते समय अनुक्रमणिका त्रुटि को कैसे ठीक किया जाए?

NeedIndexError: no matching index found. 
The suggested index for this query is: 

- kind: Message 
    properties: 
    - name: author 
    - name: ref 
    - name: date 

क्वेरी त्रुटि के बिना चलाता है अगर मैं दिनांक के आधार पर ऑर्डर करने के लिए कोशिश मत करो। डाटास्टोर इंडेक्स के तहत एपेंगेन कंसोल का कहना है:

author ▲ , ref ▲ , date ▼ 
Serving 

मैं क्या गलत कर रहा हूं? मैं अपनी क्वेरी को तिथि के अनुसार आदेश कैसे चला सकता हूं? धन्यवाद!

यहाँ मेरी इकाई परिभाषा है:

from google.appengine.ext import ndb 

class Message(ndb.Model): 
    subject = ndb.StringProperty() 
    body = ndb.TextProperty() 
    date = ndb.DateTimeProperty(auto_now_add=True) 
    ref = ndb.StringProperty(required=True) 
    author = ndb.KeyProperty(required=True) 

और इस क्वेरी कि विफल रहता है:

def readMessages(ref, user = None): 
    query = Message.query() 
    query = query.filter(Message.ref == ref) 
    if user: 
     query = query.filter(Message.author == user.key) 
    query = query.order(Message.date) 

# convert to a list so we can index like an array 
return [ message for message in query ] 

मेरे index.yaml शामिल हैं:

indexes: 

- kind: Message 
    properties: 
    - name: author 
    - name: ref 
    - name: date 
    direction: desc 

उत्तर

4

आप निर्दिष्ट करने की आवश्यकता "दिशा" के साथ-साथ "ऑर्डरिंग" तब किया जाता है जब इंडेक्स को Google की शैली में चीजों को गति देने के लिए लिखा जाता है।

indexes: 

- kind: Message 
    properties: 
    - name: author 
    - name: ref 
    - name: date 
    direction: desc 

यहाँ आदेश के बारे में Google के आधिकारिक विवरण दिया गया है:

The direction to sort, either asc for ascending or desc for descending. This is only required for properties used in sort orders of the query, and must match the direction used by the query. The default is asc.

मुझे आशा है कि इस मदद करता है

तो, अपने index.yaml की तरह होना चाहिए।

+0

धन्यवाद। असल में, मैं अपनी अनुक्रमणिका परिभाषा की आखिरी पंक्ति की प्रतिलिपि बनाना भूल गया।ऐप इंजन कंसोल इंगित करता है कि इंडेक्स को ▲, लेखक ▲, दिनांक ▼ के रूप में बनाया गया है। तो मुझे नहीं लगता कि यह मेरी समस्या है, लेकिन मैंने प्रश्न में इंडेक्स परिभाषा को अद्यतन किया है। – deltanine

3

धन्यवाद लॉरेंस, आपको मुझे सही रास्ते पर मिला - मुझे लगता है कि मुझे जवाब मिल गया है। क्वेरी को इंडेक्स परिभाषा से बिल्कुल मेल खाना चाहिए।

मुझे डेटास्टोर व्यवस्थापक बॉक्स में विभिन्न GQL क्वेरीज़ का प्रयास करके यह पता चला।

उदाहरण के लिए, निम्नलिखित 2 प्रश्न:,

no matching index found. 

The suggested index for this query is: 
- kind: Message 
    properties: 
    - name: author 
    - name: ref 
    - name: date 

हालांकि

SELECT * FROM Message where ref='' and author='' order by date desc 

सफल होता है:

SELECT * FROM Message where ref='' and author='' order by date 
SELECT * FROM Message where ref='' and author='' order by date asc 

दोनों के साथ विफल। इसी तरह, प्रश्नों जो कम पैरामीटर सूचकांक में शामिल की तुलना में भी असफल हो जायेगी, जैसे:

no matching index found. 

The suggested index for this query is: 
- kind: Message 
    properties: 
    - name: ref 
    - name: date 
    direction: desc 

तो समस्या थी मेरी क्वेरी में, लाइन:

query = query.order(Message.date) 

SELECT * FROM Message where ref='' order by date DESC 

के साथ विफल

वास्तव में आरोही क्रम में छंटनी कर रहा है, लेकिन मेरी अनुक्रमणिका में आदेश आदेश है। फिक्स है:

query = query.order(-Message.date) 
+0

आपका स्वागत है! हां यह आपकी क्वेरी और इंडेक्स ऑर्डर का सटीक मिलान होना चाहिए। –

संबंधित मुद्दे