如何在ElasticSearch中使用带通配符的术语?

时间:2014-10-29 01:24:36

标签: java elasticsearch wildcard term aster

'条款'和'通配符'由Elasticsearch提供。 “条款”是搜索多个OR条件:

        {
          "terms": {
           "IP": [
              "192.168.100.11",
              "192.168.100.13"
            ]
          }

'通配符'由*(星号)识别:

        {
          "wildcard": {
            "IP": "192.168.*.11"
          }

我想合并'通配符'+'条款'功能。我怎样才能做到这一点?例如:

        {
          "wildcard": {
           "IP": [
              "192.168.*.11",
              "192.168.*.13"
            ]
          }

1 个答案:

答案 0 :(得分:7)

您可以使用bool should部分,我认为没有"条款"像wildcardshould的查询行为类似于OR

{
  "query": {
    "bool": {
      "should": [
        {"wildcard": {"IP": "192.168.*.11"}},
        {"wildcard": {"IP": "192.168.*.13"}}
      ]
    }
  }
}