python - 在 python 中将 Elasticsearch 查询转换为 Elasticsearch-dsl

标签 python elasticsearch elasticsearch-dsl

这是一个简单有效的 Elasticsearch 查询。我必须使用 Elasticsearch dsl 模块将其转换为 python 代码。

 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

最佳答案

我终于明白了。下面是代码:

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

关于python - 在 python 中将 Elasticsearch 查询转换为 Elasticsearch-dsl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34179142/

相关文章:

node.js - Elastic Search中unicode(emoji)字符的字符串查询

database - 导出工具以在 Elasticsearch 2.3.5 索引之间通过查询复制数据

python - 我正在尝试使用 python 的 re 模块执行某些模式匹配

python - 防止 socket.getaddrinfo 'resolving' 不存在的数字主机名?

elasticsearch - Jenkins Logstash插件无法发布到ElasticSearch

ruby-on-rails - 使用搜索评分来确定 Controller 行为(轮胎/ Elasticsearch )

elasticsearch - 汇总Elasticsearch中的最后文档

elasticsearch - 将文档放入索引时Elasticsearch冲突

python - 为什么 CPython 中 id({}) == id({}) 和 id([]) == id([]) ?

python - 我们可以通过 HMM 进行监督学习吗?