0

My data "keywords" contain spaces. So "X AAA" is one "keyword". And "B AAA" is another keyword. My data will only have one of these in the actual field. So the data field will never look like a combination of the two "X AAA B AAA". There will always be just one "keyword" in the field.

Here is a sample data set of 6 rows for the field:
X AAA
Y AAA
Z AAA
X BBB
Y BBB
Z BBB

My mapping looks like this for the field

"mappings" : {
  "properties" : {
    "MYKEYWORDFIELD" : {
      "type" : "keyword"
    },
    ...

When I query the MYKEYWORDFIELD for only part of the "keyword" such as "AAA" I don't get any results. This is what I want. Thus my understanding is that the field is being treated as the entire contents of the field is one keyword. Am I understanding this correctly?

Also, I want to query MYKEYWORDFIELD for "X AAA" OR "X BBB" in a single query. Is it possible to do so? If so, how would I do so?

====
1/7/20 Update: To clarify, for the results of my query, I don't want to potentially receive rows other than those in the query. Therefore I don't believe I can use "should" which only affects result scoring and therefore may allow other rows like "Y BBB" to show up in my query.

  • You need `match_phrase` query , https://stackoverflow.com/questions/26001002/elasticsearch-difference-between-term-match-phrase-and-query-string – ᴀʀᴍᴀɴ Jan 07 '20 at 06:15
  • ```match_phrase``` doesn't allow searching for multiple values.! – Nimer Awad Jan 07 '20 at 06:34
  • can you properly format your question with exact input and expected output with some samples, so that its easy for community to help you. – Amit Jan 13 '20 at 10:42

1 Answers1

0

You can use should query, like:

{
    "query" :{
        "bool" :{
            "should": [
                {
                    "match" :{
                        "MYKEYWORDFIELD.keyword": "X AAA"
                    }
                },
                {
                    "match" :{
                        "MYKEYWORDFIELD.keyword": "X BBB"
                    }
                }
            ]
        }
    }
}
Nimer Awad
  • 3,967
  • 3
  • 17
  • 31
  • 1
    Check it now, I had to put ```match``` queries inside ```{ }``` – Nimer Awad Jan 07 '20 at 06:32
  • Thanks for the response. The way I asked the question, this is a valid solution. Unfortunately, I'm realizing I should have been more clear... my results can't contain any other rows. If I use "should", I could receive results with rows like "Y BBB" in them. – Dedicated Managers Jan 07 '20 at 17:07