0

I have a document indexed whose structure is as follows:

{
  "_index": "yelp",
  "_type": "user",
  "_id": "ABC",
  "_score": 1,
  "_source": {
    "yelping_since": "2007-07",
    "votes": {},
    "review_count": 1798,
    "name": "TEST_USER",
    "user_id": "123",
    "friends": [],
    "fans": 89,
    "average_stars": 3.48,
    "type": "user",
    "compliments": {},
    "elite": []
  }
}

When I do:

myFilter = TermFilter("_id", "ABC")
q = FilteredQuery(MatchAllQuery(), myFilter).search()
results = conn.search(query=q, indices=index_name,type=doc_typeU)

Exact result is displayed.

But when I try to search for field say user_id as follows,

myFilter = TermFilter("user_id", "123")
q = FilteredQuery(MatchAllQuery(), myFilter).search()
results = conn.search(query=q, indices=index_name,type=doc_typeU)

No results are displayed. Any idea why?

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
  • Can you post the mapping of that index? – Andrei Stefan Oct 10 '14 at 06:24
  • I think I have used default index. I haven't done or created any mapping during indexing the documents. – Anirudha Oct 10 '14 at 06:59
  • Then it should work. Haven't tested this with Pyes but in plain ES with REST calls it works as expected. – Andrei Stefan Oct 10 '14 at 07:02
  • I even tried with normal ES with doing a POST/_search. The below works { "fields" : ["name", "user_id"], "query" : { "term" : { "_id" : "ABC" } } } But this doesn't work { "fields" : ["name", "user_id"], "query" : { "term" : { "user_id" : "123" } } } Any idea how to debug or to fetch documents based on field search. Any help is appreciated. – Anirudha Oct 10 '14 at 07:21
  • Execute this `GET /yelp/user/_mapping` and update the question with the result. – Andrei Stefan Oct 10 '14 at 07:29
  • { "yelp": { "mappings": { "user": { "properties": { "average_stars": { "type": "double" }, "fields": { "type": "string" }, "name": { "type": "string" }, "query": { "properties": { "match_all": { "type": "object" }, "term": { "properties": { "user_id": { "type": "string" } } } } } – Anirudha Oct 10 '14 at 08:28
  • , "term": { "properties": { "user": { "type": "string" }, "user_id": { "type": "string" } } }, "type": { "type": "string" }, "user_id": { "type": "string" } } } } } } Divided the mapping in two comments as it was too long. Also I have removed mapping of some fields sue to space issue. Thanks. – Anirudha Oct 10 '14 at 08:29
  • There is kind of a mess in there. You used POST/_search, that's not right. It should be used with GET. Also, you have in the mapping a field called "query" and another one called "term". I suspect this is because you used POST/_search. I suggest starting over with your mapping (delete the index, create it again, add data and test). – Andrei Stefan Oct 10 '14 at 08:41
  • try this >>> TermFilter("_user_id", "123") _ (undescore infornt of user_id) – Remis Haroon - رامز Aug 25 '15 at 10:59

1 Answers1

0

please try this one

myFilter = TermQuery("user_id", "123")
q = FilteredQuery(MatchAllQuery(), myFilter).search()
results = conn.search(query=q, indices=index_name,type=doc_typeU)