0

I'd like to search items that either have firstField (mapped as text) similar to a query string or secondField (mapped as an integer) equal to 1.

After reading the docs, I understand I should be using bool with should (as noted here):

{
  "query": {
    "bool": {
      "should": [
        {"match": {"firstField":  "queryString"}},
        {"term":  {"secondField": 1}}
      ]
    }
  }
}

The results however show that secondField contributes far less to the result than firstField does since their scoring algorithms produce different scales.

I am considering artifically boosting the secondField (though I am guessing this would only work in some cases) or normalizing firstField to somehow represent a percentage instead of an arbitrary score.

Is there a proper way to give each field the same weight?

Note: I am using ES 7.x.

Kathandrax
  • 685
  • 8
  • 25

1 Answers1

0

Seems like you don't want scoring to happen. I such case use filter context.

{
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "should": [
              {
                "match": {
                  "firstField": "queryString"
                }
              },
              {
                "term": {
                  "secondField": 1
                }
              }
            ]
          }
        }
      ]
    }
  }
}
Nishant
  • 6,175
  • 1
  • 13
  • 27
  • Thanks for the suggestion, but I do want scoring to happen. I'd like the fields to be scored according to the same scale (e.g. 0 to 1, 1 being a perfect `match` or positive `term`, 0 being totally irrelevant) so that I can give precedence to one compared to the other. – Kathandrax Nov 06 '19 at 13:57