如何在elasticsearch中的_type字段上应用正则表达式

时间:2017-11-30 06:42:42

标签: java elasticsearch

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 1,
        "hits": [
            {
                "_index": "index_name",
                "_type": "type_6831397832239852729",
                "_id": "a~~b~c~~d",
                "_score": 1,
                "_source": { <Data>}
            },
            {
                "_index": "index_name",
                "_type": "type_-8642158362232960463",
                "_id": "a~~b~c~~d",
                "_score": 1,
                "_source": {
                <date>
                }
            }
        ]
    }
}

我在一个索引下有两个文档,_id相同但_type不同。如何使用java API在_type上应用正则表达式?

例如: - 我希望搜索_type=type_* and _id = a~~b~c~~d

1 个答案:

答案 0 :(得分:0)

您似乎可以像普通字段一样查询它。我在这里把它放在query_string搜索中。

{  
   "query":{  
      "bool":{  
         "must":[  
            {  
               "query_string":{  
                  "query":"_type:type_*"
               }
            },
            {  
               "term":{  
                  "_id":"a~~b~c~~d"
               }
            }
         ]
      }
   }
}