Skip to content

Instantly share code, notes, and snippets.

@josephbuchma
Last active March 27, 2017 13:11
Show Gist options
  • Save josephbuchma/49ccc273cfd2cfc1a10e572c22314daf to your computer and use it in GitHub Desktop.
Save josephbuchma/49ccc273cfd2cfc1a10e572c22314daf to your computer and use it in GitHub Desktop.
{
  "index": "wsx5_answers",
  "type": "topics",
  "body": {
    "stored_fields": ["title"],
    "size": 15,
    "from": 0,
    "query": {
      "match" : {
         "field1" : {
            "operator" : "or",
            "query" : "the quick brown",
            "type" : "boolean"
         }
      },
      "bool": {
        "must": {
          "match_all": {}
        },
        "filter": {
          "bool": {
            "must": [
              {
                "terms": {
                  "status": ["approved"]
                }
              },
              {
                "terms": {
                  "type": ["question", "idea", "praise", "update", "info", "bug", "faq", "tipsandtricks"]
                }
              },
              {
                "term": {
                  "author": 12345
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "term": {
                        "public": true
                      }
                    },
                    {
                      "term": {
                        "author": 12345
                      }
                    }
                  ]
                }
              },
              {
                "terms": {
                  "lang": ["it"]
                }
              }
            ]
          }
        }
      }
    },
   // rescore may be object if only one rescore needed
   "rescore" : [
     // Basic query rescore
     {
        "window_size" : 50,
        "query" : {
           "rescore_query" : {
              "match" : {
                 "field1" : {
                    "query" : "the quick brown",
                    "type" : "phrase",
                    "slop" : 2
                 }
              }
           },
           "query_weight" : 0.7,
           "rescore_query_weight" : 1.2
        }
      },
      // Function rescore (single function)
      {
        "window_size" : 50,
        "query" : {
           "rescore_query" : {
             "function_score": {
               "query": {
                  // query to pick already queried records for rescoring
               }
               "FUNCTION_NAME": {

               }
             },
           },
           "query_weight" : 0.7,
           "rescore_query_weight" : 1.2
        }
      },
      // Function rescore (multiple functions)
      {
        "window_size" : 50,
        "query" : {
           "rescore_query" : {
             "function_score": {
               "query": {
                  // query to pick already queried records for rescoring
               }
               "functions": [
                 {
                   "filter":{}, // optional filtering
                   "FUNCTION_1": {

                   }
                 },
                 {
                   "filter":{}, // optional filtering
                   "FUNCTION_2": {

                   }
                 },
               ]
             },
           },
           "query_weight" : 0.7,
           "rescore_query_weight" : 1.2
        }
      },
    ],
    // if sort present rescore is ignored
    "sort": {
      "lastupdate": {
        "order": "desc"
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment