es 搜索
{ "query": { "bool": { "must": [ { "match": { "grade": "00cr12" } }, { "nested": { "path": "attrs", "query": { "bool": { "must": [ { "match": { "attrs.name": "c" } }, { "match": { "attrs.maxv": "18" } }, { "match": { "attrs.attrId": "10" } } ] } } } }, { "nested": { "path": "attrs", "query": { "bool": { "must": [ { "match": { "attrs.name": "p" } }, { "match": { "attrs.maxv": "28" } }, { "match": { "attrs.attrId": "11" } } ] } } } } ] } } }
查看 http://192.168.0.166:9200/test/col/_mapping?pretty
先新建一个,在创建之前修改类型
curl -XPOST "http://192.168.0.166:9200/test/col/_mapping?pretty" -d '{
"col": {
"properties": {
"attributeCategoryId": {
"type" : "string"
}
}
}
}'
在list attrs后添加 "type": "nested",这样就可以搜索list里面单独的对象的内容了
curl -XPOST "http://192.168.0.166:9200/matmass_test/col/_mapping?pretty" -d '{ "col" : { "properties" : { "attrs" : { "type": "nested", "properties" : { "attrId" : { "type" : "long" }, "maxv" : { "type" : "long" }, "minv" : { "type" : "long" }, "name" : { "type" : "string" }, "tmplate" : { "type" : "long" } } }, "grade" : { "type" : "string" } } } }'
配置最大读取数
curl -XPUT http://192.168.0.166:9200/索引名/_settings -d '{ "index" : { "max_result_window" : 100000000}}'
参考
java api 动态条件拼接 http://blog.youkuaiyun.com/sampson_lee/article/details/46771165