0
votes

I am having a problem while querying elastic search. The below is my query

GET _search {
"query": {
    "bool": {
        "must": [{
                "match": {
                    "name": "SomeName"
                }
            },
            {
                "match": {
                    "type": "SomeType"
                }
            },
            {
                "match": {
                    "productId": "ff134be8-10fc-4461-b620-79s51199c7qb"
                }
            },
            {
                "range": {
                    "request_date": {
                        "from": "2018-08-22T12:16:37,392",
                        "to": "2018-08-28T12:17:41,137",
                        "format": "YYYY-MM-dd'T'HH:mm:ss,SSS"
                    }
                }
            }

        ]
    }
}
}

I am using three match queries and a range query in the bool query. My intention is getting docs with these exact matches and with in this date range. Here , if i change name and type value, i wont get the results. But for productId , if i put just ff134be8, i would get results. Anyone knows why is that ? . The exact match works on name and type but not for productId

1
Could you also post your mappings? Which elasticsearch version do you use? By the way if you need the exact checks, you should implement a term query instead of a match oneEirini Graonidou
could please give some more information about your query like are you using kibana or any java client to fetch informationharkesh kumar
@EiriniGraonidou , i am not using any mappings. AWS kinesis is writing the entry to ES. depends on the data we pass, it creates the mapping automaticallyJava Programmer

1 Answers

2
votes

You need to set the mapping of your productId to keyword to avoid the tokenization. With the standard tokenizer "ff134be8-10fc-4461-b620-79s51199c7qb" will create ["ff134be8", "10fc", "4461", "b620", "79s51199c7qb"] as tokens.

You have different options :

1/ use a term query to check without analyzing the content of the field

...
    {
        "term": {
            "productId": "ff134be8-10fc-4461-b620-79s51199c7qb"
        }
    },
    ...

2/ if you are in Elasticsearch 6.X you could change your request to

...
{
    "match": {
        "productId.keyword": "ff134be8-10fc-4461-b620-79s51199c7qb"
    }
},
...

As elasticsearch will create a subfield keyword with the type keyword for all string field

The best option is, of course, the first one. Always use term query if you are trying to match the exact content.