2015-12-09 79 views
2

這是一個簡單的彈性工作搜索查詢。我必須使用彈性搜索dsl模塊將其轉換爲python代碼。將彈性搜索查詢轉換爲python中的Elasticsearch-dsl

GET indexforproject/project/_search 
    { 
    "query": { 
     "filtered": { 
     "query": {"match_all": {}}, 
     "filter": { 
      "term": { 
      "project_language.languageName.raw": "nodejs" 
      } 
     } 
     } 
    } 
    } 

這是我用來

from elasticsearch import Elasticsearch 
    from elasticsearch_dsl import Search,Q,query,F 
    client = Elasticsearch([{'host':'blrkec248770d','port':'9200'}]) 
    temp="Internal" 
    s=Search(using=client, index="indexforproject").filter("term","project_language.languageName.raw"="Internal") 
    body={ 
    'query':"PHP and node.js", 
    'filters':[{'name':"languages",'values':"[python,PHP,angular]"} ] 
    } 


    response=s.execute() 
    for hit in response: 
     print hit.title 

回答

2

我終於得到它。以下是代碼:

from elasticsearch import Elasticsearch 
    from elasticsearch_dsl import Search,Q,query,F 
    client = Elasticsearch([{'host':'blrkec248770d','port':'9200'}]) 
    d={'project_language.languageName.raw':'nodejs'} 
    s=Search(using=client, index="indexforproject").filter('term',**d) 
    body={ 
    'query':"PHP and node.js", 
    'filters':[{'name':"languages",'values':"[python,PHP,angular]"} ] 
    } 

    #print s.to_dict() 
    response=s.execute() 
    for hit in response: 
     print hit.title