elasticsearch 使用字词筛选多个值时未获取输出

cbjzeqam  于 2023-01-25  发布在  ElasticSearch
关注(0)|答案(1)|浏览(98)

我在OpenSearch中有一个表,其中每个字段的格式都是“文本”。
我的table就是这个样子

现在我在opensearch中运行的query(q1)看起来是这样的。我没有得到任何输出。但是当我运行query q2时,我得到了输出。

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"}}]}}}

现在我想在prov_type上应用多重过滤。我已经尝试过在列表中使用prov_type的术语,比如['A','B']。
有人能回答这个问题吗?如何在opensearch/elasticsearch中对单列的值应用多个过滤器每个字段的数据类型都是文本。已经尝试过了-How to filter with multiple fields and values in elasticsearch?
索引的Map

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
            }
          }
        }
      }
    }
  }
}

如果你需要更多的信息,请告诉我

enyaitl3

enyaitl31#

您可以使用should查询来筛选具有OR条件的数据。

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

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

相关问题