使用Elasticsearch匹配/映射列表

时间:2019-03-23 03:50:50

标签: python elasticsearch

mongodb中有一个列表, 例如:

db_name = "Test"
collection_name = "Map"
db.Map.findOne()

{
  "_id" : ObjectId(...),
  "Id" : "576",
  "FirstName" : "xyz",
  "LastName" : "abc",
  "skills" : [
               "C++",
               "Java",
               "Python",
               "MongoDB",
             ]
}

elastcisearch索引中有一个列表(我正在使用kibana来执行查询)

GET /user/_search

{
  "took" : 31,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 7,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "customer",
        "_type" : "_doc",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "name" : "xyz abc"  
          "Age" : 21,
          "skills" : [
                        "C++",
                        "Java",
                        "Python",
                        "MongoDB", 
                     ]  
        }
      }, 
     ]
    }
}

任何人都可以通过基于技能的弹性搜索查询来匹配这两个记录。 我正在使用python编写代码

如果找到匹配项,我将尝试获取该用户的名字和姓氏

First name : "xyz"
Last name : "abc"

1 个答案:

答案 0 :(得分:0)

假设您要为所有文档建立弹性索引,并且要匹配其中skills同时具有javamongodb的文档,查询将为:

{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "skills": "mongodb"
          }
        },
        {
          "term": {
            "skills": "java"
          }
        }
      ]
    }
  }
}