一、查询(_search)
例如,查询index 和 type 为idx_ot的所有文档,下面的例子忽略curl中的公共部分,只展示query部分
curl -XPOST -H "Content-Type: application/json" -H "Authorization: xxx "
http://11.5.44.232:40002/idx_ot/idx_ot/_search?pretty -d '{
"query": {
"match_all": {}
}
}'
1.比较两个字段不同
{
"query":{
"bool":{
"filter":{
"script":{
"script":{
"source":"doc['modifyTime'].value != doc['createTime'].value",
"lang":"painless"
}
}
}
}
}
}
查询modifyTime和createTime不相同的文档
2. 范围查询
{
"query":{
"bool":{
"must":[
{
"range":{
"otQuestionId":{
"gt":"340",
"lt":"364"
}
}
}
]
}
}
}
3. 嵌套查询
{
"query":{
"bool":{
"must":[
{
"term":{
"id":"1d061e26-10b7-489b-9d2e-296a9b5d78c0"
}
},
{
"nested":{
"path":"answers",
"query":{
"bool":{
"must":[
{
"term":{
"answers.id":"1d061e26-10b7-489b-9d2e-296a9b5d78c0"
}
}
]
}
}
}
}
]
}
}
}
二、更新(_update_by_query)
查询的 cid2="大家电",cid3="空调" 对应文档的status字段全部更新为'0'(每个文档都有cid2、cid3、status三个字段)
curl -XPOST -H "Content-Type: application/json" -H "Authorization: Basic xxx"
http://11.5.43.37:40000/deep_migration_dev/deep_migration_dev/_update_by_query?
pretty -d
'{
"query": {
"bool": {
"must": [
{
"term": {
"cid2": "大家电"
}
},
{
"term": {
"cid3": "空调"
}
}
]
}
}
,
"script": {
"lang": "painless",
"inline": "ctx._source.status = '0' "
}
}'
三、删除( _delete_by_query )
把 cid2="大家电",cid3="空调" 对应文档全部删除
curl -XPOST -H "Content-Type: application/json" -H "Authorization: Basic xxx "
http://11.5.43.37:40000/deep_migration_dev/deep_migration_dev/_delete_by_query?
pretty -d '{
"query": {
"bool": {
"must": [
{
"term": {
"cid2": "大家电"
}
},
{
"term": {
"cid3": "空调"
}
}
]
}
}
}'
四、增加
增加一个文档不需要指定id,如何指定则会覆盖之前的id的文档。
curl -XPOST -H "Content-Type: application/json" -H "Authorization: Basic xxx"
http://11.5.43.37:40000/deep_migration_dev/deep_migration_dev/?pretty -d
'{
"question": "能不能推荐一下款一级能效,价格实惠的",
"answerSeg": "稍等",
"updateTime": 1538140001000,
"source": "3",
"version": "2018",
"answer": "稍等",
"createTime": 1547540720477,
"extend2": "1000001452",
"questionSeg": "能 不能 推荐 一 下款 一级 能效 价格 实惠 的",
"cid2": "大家电",
"cid3": "空",
"id": "Rule_611255",
"shopId": "50271",
"tag": "能耗",
"sku": "3968191",
"brand": "美",
"cid1": "家用电器",
"status": 0
}'