4

This is a simple working elastic search query. I have to convert this into a python code using elastic search dsl module.

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

This is what i used

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

1 Answer 1

3

I finally got it. Below is the code :

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.