在特定字段上的Pyes搜索没有结果

时间:2014-10-10 01:58:20

标签: elasticsearch pyes

我有一个索引的文档,其结构如下:

{
  "_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": []
  }
}

当我这样做时:

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

显示确切的结果。

但是当我尝试按如下方式搜索字段说user_id时,

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

未显示任何结果。知道为什么吗?

1 个答案:

答案 0 :(得分:0)

请尝试这个

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