2017-06-19 96 views
0

我想使用特定类型的ID获取文档。例如,现在我已经在Sense中编写了这个查询。此查询将返回类型产品中带有这些id的所有文档。在elasticsearch中搜索多种类型的多个ID

POST /_search 
    { 
     "query": { 
      "ids" :{ 
       "type" : "product", 
       "values" : ["100005","10002010093"] 
     } 
     } 
    } 

但我想要的这里是这样

POST /_search 
     { 
      "query": [ 
      { 
       "ids" :{ 
        "type" : "product", 
        "values" : ["100005","10002010093"] 
      } 
      }, 
      { 
       "ids" :{ 
        "type" : "store", 
        "values" : ["100003","1000201"] 
      } 
      } 
     ] 
     } 

POST /_search 
     { 
      "query":{ 
       "ids" :[ 
        { 
        "type" : "product", 
        "values" : ["100005","10002010093"] 
        }, 
        { 
        "type" : "store", 
        "values" : ["100003","1000201"] 
        } 
       ] 
      } 
     } 

有没有办法把它做?

回答

1

你只需要使用bool/filter query

POST /_search 
{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "ids": { 
      "type": "product", 
      "values": [ 
       "100005", 
       "10002010093" 
      ] 
      } 
     }, 
     { 
      "ids": { 
      "type": "store", 
      "values": [ 
       "100003", 
       "1000201" 
      ] 
      } 
     } 
     ] 
    } 
    } 
} 
+0

它不能正常工作,它返回此响应。 '{ “花”:13, “TIMED_OUT”:假的, “_shards”:{ “总”:25, “成功”:25, “失败”:0 }, “点击” :{ “总”:0, “MAX_SCORE”:空, “点击”:[] } }' 而且我相信,我所提供的ID存在。 –

+0

我的不好,你需要使用'should'而不是'filter',请重试。 – Val

+0

现在可以使用了!谢谢! –

相关问题