如何从elasticsearch获取数据?

时间:2015-10-05 23:55:41

标签: elasticsearch

这是弹性搜索查询,以获取owner1First为Donald且owner2Last为Brown的文档。但是这个查询会将所有文档作为结果并且不会过滤。

curl -XGET "http://localhost:9200/test2/extract/_search" -d"
{"query" :
 {"filtered" :
  { "filter" : 
   {"bool" :
    {"should" :
     [{ "term" :
       {"owner1First" :"Donald"}},
       { "term" :{"owner1Last" : "Brown"}} 
     ]
       }
      }
     }
    }
   }"

1 个答案:

答案 0 :(得分:3)

您需要更改为bool/must

curl -XGET 'http://localhost:9200/test2/extract/_search' -d '{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [        <---- use must here !
            {
              "term": {
                "owner1First": "donald"
              }
            },
            {
              "term": {
                "owner1Last": "brown"
              }
            }
          ]
        }
      }
    }
  }
}'