0

I have the following mapping:

{
  "events": {
    "mappings": {
      "event": {
        "Type of Event": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

And the following data inside the index

{
  "Type of Event": "Orientation Session"
},
{
  "Type of Event": "Orientation Tutorial"
}

I am trying to match only those with Type of Event == "Orientation Session".

I'm trying the following query:

{
  "query": {
    "term": {
      "Type of Event.keyword": "Orientation Session"
    }
  }
}

but it doesn't match anything. It does, however, work if there are no spaces in the string. I can't use match query here, as it would match both events.

What am I doing wrong? I've seen a lot of discussion on spaces in term queries, but none about using keyword. They all are specific to elasticsearch 2.0.

1 Answer 1

1

The problem is that your mapping is wrong, you're missing the properties keyword.

If you try to create your index with the mapping you gave, you should get the following error:

unknown setting [index.events.mappings.event.Type of Event.fields.keyword.ignore_above] please check that any required plugins are installed, or check the breaking changes documentation for removed settings

So you need to use the following mapping instead, and it will work:

{
  "mappings": {
    "event": {
      "properties": {             <--- this was missing
        "Type of Event": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}
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.