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

3
  • Can you share GET <index_name>/_mapping Commented Jan 23, 2023 at 10:34
  • @MusabDogan Done. Please have a look Commented Jan 23, 2023 at 11:32
  • Thanks for sharing. Is the below answer what you are looking for? Commented Jan 23, 2023 at 12:24

1 Answer 1

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.

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.