0

I have a filter query as shown below. I intend to filter on stripped-blocked-uri (exact match) which is not working,

{
    "query": {
        "bool": {
            "filter": [
                {
                    "term": {
                        "stripped-blocked-uri": "https://www.twitter.com:9090"
                    }
                },
                {
                    "term": {
                        "project-id": "1"
                    }
                },
                {
                    "term": {
                        "rule-id": "101"
                    }
                }
            ]
        }
    }
}

which is returning no hits.

My mapping is,

                    "stripped-blocked-uri": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },

Not sure what is going wrong here. Please help!

z3r0
  • 93
  • 6

1 Answers1

1

Use the keyword field:

{
    "query": {
        "bool": {
            "filter": [
                {
                    "term": {
                        "stripped-blocked-uri.keyword": "https://www.twitter.com:9090"
                    }
                },
                {
                    "term": {
                        "project-id": "1"
                    }
                },
                {
                    "term": {
                        "rule-id": "101"
                    }
                }
            ]
        }
    }
}
Joe - GMapsBook.com
  • 15,787
  • 4
  • 23
  • 68
  • thanks that worked! Sorry but I am new to elastic search and I do not understand the use of .keyword. Can you please elaborate? I know of the keyword data type but not about this. – z3r0 Apr 17 '20 at 10:59
  • 1
    No prob. It's already elaborated on here and elsewhere: https://stackoverflow.com/a/52845279/8160318 – Joe - GMapsBook.com Apr 17 '20 at 11:10