我已将1000张汽车记录批量放入ElasticSearch。
{ "index" : { "_index" : "car", "_type" : "car", "_id" : "1" } }
{"id":1,"car_make":"Chevrolet","car_model":"Express","car_year":2012,"car_color":"Goldenrod","made_in":"Indonesia"}
{ "index" : { "_index" : "car", "_type" : "car", "_id" : "2" } }
{"id":2,"car_make":"BMW","car_model":"Z8","car_year":2002,"car_color":"Fuscia","made_in":"China"}
{ "index" : { "_index" : "car", "_type" : "car", "_id" : "3" } }
...
...
...
当我运行以下内容时,我希望得到一些结果,但现在我的结果为零。
>> curl -XGET 'localhost:9200/car/car/_search?pretty' -H 'Content-Type: application/json' -d'
> {
> "query": {
> "bool": {
> "must": { "match_all": {} },
> "filter": {
> "terms": {
> "car_make": ["BMW","Lexus"]
> }
> }
> }
> }
> }
>
> '
{
"took" : 18,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
答案 0 :(得分:0)
您是否为car
(索引/类型)创建了自定义映射?如果没有,它将默认为text
keyword
字段类型(如果您使用es 5.x无法记住确切版本)。
如果是这种情况,你可以尝试:
{
"query": {
"bool": {
"filter": {
"terms": {
"car_make.keyword": ["BMW","Lexus"]
}
}
}
}
}