0

I have a table in opensearch in which the format of every field is "text".

This is how my table looks like

enter image description here

Now the query(q1) which I am running in opensearch looks like this. i am not getting any output. But when I run query q2 then I get the output.

q1 = {"size":10,"query":{"bool":{"must":[{"multi_match":{"query":"cen","fields":["name","alias"],"fuzziness":"AUTO"}}],"filter":[{"match_phrase":{"category":"Specialty"}},{"match_phrase":{"prov_type":"A"}},{"match_phrase":{"prov_type":"C"}}]}}}

q2 = {"size":10,"query":{"bool":{"must":[{"multi_match":{"query":"cen","fields":["name","alias"],"fuzziness":"AUTO"}}],"filter":[{"match_phrase":{"category":"Specialty"}},{"match_phrase":{"prov_type":"A"}}]}}}

Now I want to apply multiple filtering on prov_type. I have tried using terms also with prov_type in list like ['A','B'].

Can anyone please answer this on how to apply multiple filters on value for single column in opensearch/elasticsearch. Datatype for every field is text. Have already tried this - How to filter with multiple fields and values in elasticsearch?

Mapping for the index

GET index/_mapping

{
  "spec_proc_comb_exp" : {
    "mappings" : {
      "properties" : {
        "alias" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "category" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "prov_type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "specialty_code" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

Please let me know in case you need anymore information

BrownBatman
  • 171
  • 1
  • 3
  • 14

1 Answers1

0

You can use the should query to filter your data with the OR condition.

Should: The clause (query) should appear in the matching document.

GET test_allergy/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "prov_type": "A"
          }
        },
        {
          "term": {
            "prov_type": "C"
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

Note: You can set minimum_should_match as a number or percentage.

Musab Dogan
  • 1,811
  • 1
  • 6
  • 8