Filter and sort documents based on nested fields


(Allan Benguigui) #1

Hi everyone,

I'm using Elasticsearch to search easily people based on theirs skills.
I tried to find answer of my question in related post, but I did not.

Here is what a document looks likes:

{
      "_index" : "danny-index-node",
      "_type" : "user",
      "_id" : "c6ddfe51-c2fa-11e8-bdc5-fa163e1c0c40",
      "_score" : 3.757271,
      "_source" : {
        "lastName" : [ ],
        "domainsCity" : [ ],
        "domainsTwitter" : [ ],
        "githubJobs" : [ ],
        "stackBio" : [ ],
        "stackJobs" : [ ],
        "stackPicture" : [ ],
        "signaturePhones" : [ ],
        "domainSectors" : [ ],
        "uuid" : "XXX",
        "emails" : [ "XXX@gmail.com" ],
        "skills" : [ {
          "github" : 1.5,
          "name" : "CSS",
          "stackoverflow" : 0
        }, {
          "github" : 3.08,
          "name" : "HTML",
          "stackoverflow" : 0
        }, {
          "github" : 0.03,
          "name" : "PHP",
          "stackoverflow" : 0
        }, {
          "github" : 0.11,
          "name" : "TeX",
          "stackoverflow" : 0
        }, {
          "github" : 6.46,
          "name" : "R",
          "stackoverflow" : 0
        } ],
        "hasEmail" : 1,
        "githubPicture" : [ "https://avatars1.githubusercontent.com/u/XXX" ],
        "gravatar" : [ "" ],
        "domainsName" : [ ],
        "id" : XXX,
        "signatureJobs" : [ ],
        "domainsCountry" : [ ],
        "domainsDescription" : [ ],
        "gmailName" : "john smith",
        "signatureAddresses" : [ ],
        "stackCompany" : [ ],
        "domainTags" : [ ],
        "linkedinLocation" : [ ],
        "jobs" : [ ],
        "githubBio" : [ "synthetic biologist, plant engineer, reproducible research enthusiast" ],
        "domains" : [ ],
        "linkedinSchool" : [ ],
        "linkedinCompany" : [ ],
        "domainsLinkedin" : [ ],
        "socialAccounts" : [ {
          "label" : [ "SocialAccountGH" ],
          "id" : "johnsmith"
        } ],
        "stackReach" : [ ],
        "stackLocation" : [ ],
        "firstName" : [ ],
        "domainIndustry" : [ ],
        "domainsCrunchbase" : [ ],
        "githubLocation" : [ "Seattle" ],
        "githubFollowers" : [ 4 ],
        "name" : [ "john smith" ],
        "linkedinJobs" : [ ],
        "linkedinPicture" : [ ],
        "typeConnexion" : "gmail",
        "githubCompany" : [ "University of Washington" ]
      }
    }

I'm trying to get People who have great skills in R AND Javascript, based on their github/stackoverflow value.

Here is my query :

{
    "size": 10,
    "from": 0,
    "query": {
        "filtered": {
            "query": {
                "nested": {
                    "path": "skills",
                    "query": {
                        "function_score": {
                            "query": {
                                "terms": {
                                    "skills.name":  ["r","javascript"]
                                    
                                }
                            },
                            "functions": [
                                {
                                    "field_value_factor": {
                                        "field": "skills.github",
                                        "factor": 1.5 
                                    }
                                },
                                {
                                    "field_value_factor": {
                                        "field": "skills.stackoverflow",
                                        "factor": 1.2 
                                    }
                                }
                                ],
                            "boost_mode": "sum"
                        }
                    }
                }
            }
        }
    }
}

Unfortunately, I got wrong result, the query tries to find people with at least one of the skills R or javascript and not having both skills. And secondly the first document is not the one who have the better score in R or Javascript.

Can anyone explain me how to deal with this query?

Thank you


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.