0

I have an elasticsearch query that isn't matching a document that it should.

Here is the query:

POST _search
{
   "query": {
      "filtered": {
         "filter": {
            "bool": {
               "must": {
                  "term": {
                     "signupCompany": "NewBay Media"
                  }
               }
            }
         }
      }
   }
}

However, if I change the term to:

"signupCompanyID": 643

Then it finds the correct document. Here is my mapping:

"properties": {
      "body": {
        "type": "string"
      },
      "datetimeIndexed": {
        "type": "date",
        "format": "epoch_millis||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
      },
      "datetimeReceived": {
        "type": "date",
        "format": "epoch_millis||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
      },
      "duplicateOfEmailID": {
        "type": "long"
      },
      "enabled": {
        "type": "boolean"
      },
      "htmlBodyPath": {
        "type": "string"
      },
      "plainBodyPath": {
        "type": "string"
      },
      "secondsAgoReceived": {
        "type": "long"
      },
      "senderName": {
        "type": "string",
        "fields": {
          "raw": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      },
      "signupCompany": {
        "type": "string"
      },
      "signupCompanyEnabled": {
        "type": "boolean"
      },
      "signupCompanyID": {
        "type": "long"
      },
      "signupCompanyInitial": {
        "type": "string"
      },
      "subject": {
        "type": "string"
      }
    }

I have some other queries that are already working and in production, using the datetimeReceived field and enabled field, but haven't been able to get this particular string match to work.

It won't work with any signupCompany, not just this one.

1

1 Answer 1

1

You need to set the mapping type for signupCompany to not_analyzed so that it doesn't try to match a partial string, only the exact value. - docs: https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html

"signupCompany": {
  "type":     "string",
  "index":    "not_analyzed"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.