Skip to content

Instantly share code, notes, and snippets.

@hkulekci
Last active September 9, 2023 09:00
Show Gist options
  • Save hkulekci/53d15322dd83b18d14e126207c8b51ff to your computer and use it in GitHub Desktop.
Save hkulekci/53d15322dd83b18d14e126207c8b51ff to your computer and use it in GitHub Desktop.

Revisions

  1. hkulekci revised this gist Sep 9, 2023. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions terms_set_query.md
    Original file line number Diff line number Diff line change
    @@ -76,4 +76,36 @@ GET job-candidates/_search
    }
    }
    }
    PUT /job-candidates/_doc/5?refresh
    {
    "name": "Mason Difficult",
    "programming_languages": [ "java", "php"]
    }
    GET /job-candidates/_search
    {
    "query": {
    "terms_set": {
    "programming_languages": {
    "terms": [ "java", "php" ],
    "minimum_should_match_script": {
    "source":
    """
    if (doc['required_matches'].size() != 0) {
    params['min_requires'] = doc['required_matches'].value
    }
    return params['min_requires'];
    """,
    "params": {
    "min_requires": 2
    }
    }
    }
    }
    }
    }
    ```
  2. hkulekci revised this gist Sep 9, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion terms_set_query.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    ```
    DELETE job-candidates
    PUT job-candidates
    @@ -74,4 +75,5 @@ GET job-candidates/_search
    }
    }
    }
    }
    }
    ```
  3. hkulekci created this gist Sep 9, 2023.
    77 changes: 77 additions & 0 deletions terms_set_query.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    DELETE job-candidates

    PUT job-candidates
    {
    "mappings": {
    "properties": {
    "name": {
    "type": "keyword"
    },
    "programming_languages": {
    "type": "keyword"
    },
    "required_matches": {
    "type": "long"
    }
    }
    }
    }


    PUT job-candidates/_doc/1?refresh
    {
    "name": "Jane Smith",
    "programming_languages": [ "c++", "java" ],
    "required_matches": 2

    }


    PUT job-candidates/_doc/2?refresh
    {
    "name": "Jason Response",
    "programming_languages": [ "java", "php" ],
    "required_matches": 2
    }

    PUT /job-candidates/_doc/3?refresh
    {
    "name": "Jason Request",
    "programming_languages": [ "rust", "php" ],
    "required_matches": 1
    }

    PUT /job-candidates/_doc/4?refresh
    {
    "name": "Mason Difficult",
    "programming_languages": [ "javascript", "php", "html"],
    "required_matches": 3
    }


    GET job-candidates/_search

    GET job-candidates/_search
    {
    "query": {
    "terms_set": {
    "programming_languages": {
    "terms": ["c++", "java", "php"],
    "minimum_should_match_field": "required_matches"
    }
    }
    }
    }


    GET job-candidates/_search
    {
    "query": {
    "terms_set": {
    "programming_languages": {
    "terms": ["java", "php"],
    "minimum_should_match_field": "required_matches"
    }
    }
    }
    }