0
votes

I've got a large person index built for Elasticsearch (1.7.3)

I'm trying to search the person information (few tens of millions). Person's gender (which is 'M' or 'F') is one of many fields in the person document.

When I search using the match query, it takes ages (which I'm guessing it has to collate a large number of postings lists?) cause there might be atleast a million of either gender. Is this a valid observation?

I'm doing a match query because I want the score.

{
  "explain": true,
  "from": 0,
  "size": 10,
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "Gender": {
                  "query": "F",
                  "boost": 10.0
                }
              }
            }
          ]
        }
      }
    }
  }
}

I understand that filters are very fast and more suited for this (and cached too). Is there any way I could wrap this in a filter and say if it matched then give it a fixed score of 10 (for example)?

Or could I stick on with match query and explore within? Any help/pointers would be much appreciated.

1

1 Answers

0
votes

You might want to look into function score

Also I feel you should map your gender field as not_analyzed and then you query would look something like this

GET your_index/your_type/_search
{
  "query": {
    "function_score": {
      "query": {
        "match_all": {}
      },
      "functions": [
        {
          "filter": {
            "term": {
              "Gender": "F"
            }
          },
          "weight": 10
        }
      ],
      "score_mode": "multiply"
    }
  }
}

This will boost documents with gender F

Does this help?