`

elastic search开发笔记

阅读更多

1,可使用chrome的插件Sense进行elastic search数据的插入及查询工作:

{
            "_index": "nadeals-2016.07.18",
            "_type": "default",
            "_id": "1287232256009_191903608097",
            "_score": 1.7590221,
            "_source": {
               "seller_name": "filafactory",
               "buyer_id": "1507302688",
               "plan_gmv": 19.99,
               "vertical": "Fashion",
               "item_title": "FILA Men's Countdown",
               "qty": 1,
               "transaction_id": "1287232256009",
               "timestamp": 1468833332000,
               "subsidy": 4,
               "stock": 9892,
               "price": "USD19.99",
               "start": 1468249200000,
               "item_id": 191903608097,
               "seller_country": "US",
               "module_name": "Best of Fashion up to 80% Off",
               "subsidized": true,
               "end": 1468853940000,
               "@version": "1",
               "@timestamp": "2016-07-18T09:16:11.247Z"
            }
         }

 

2,建立index, 定义_type,对字段类型设定mapping.

PUT /nadeals-2016.07.18
{         
"mappings" : {
    "default" : {       
        "properties" : {
            "module_name": {
               "type": "string",
               "index":"not_analyzed"
            },
            "seller_name": {
               "type": "string",
               "index":"not_analyzed"
            },
            "buyer_id": {
               "type": "string",
               "index":"not_analyzed"
            },
             "vertical": {
               "type": "string",
               "index":"not_analyzed"
            },
             "item_title": {
               "type": "string",
               "index":"not_analyzed"
            },
              "price": {
               "type": "string",
               "index":"not_analyzed"
            },
              "seller_country": {
               "type": "string",
               "index":"not_analyzed"
            }
        }
    }
}
}

 

3,insert及update操作:

put /nadeals-2016.07.18/default/727611992025_380899294777
{
"seller_name": "snowdealsnow",
               "buyer_id": "1336337409",
               "plan_gmv": 13.99,
               "vertical": "Fashion",
               "item_title": "NEW Electric Rockabye Womens Fashion Designer Oversize Sunglasses Msrp$100",
               "qty": 1,
               "transaction_id": "727611992025",
               "timestamp": 1468833303000,
               "subsidy": 0,
               "stock": 614,
               "price": "USD15.99",
               "start": 1468422000000,
               "item_id": 380899294777,
               "seller_country": "US",
               "module_name": "Multi Vert 7.13 thru 7.20",
               "subsidized": false,
               "end": 1469026740000,
               "@version": "1",
               "@timestamp": "2016-07-18T09:15:18.242Z"
}

 

4,delete操作

DELETE /nadeals-2016.07.18/default/727611992025_380899294777

 

5,查询操作

GET /nadeals-2016.07.18/default/_search
{
  "query" : {
    "bool" : {
      "must" : [ {
        "range" : {
          "timestamp" : {
            "from" : 1468833200000,
            "to" : 1468836200000,
            "format" : "epoch_millis",
            "include_lower" : true,
            "include_upper" : true
          }
        }
      }, {
        "term" : {
          "seller_country" : "US"
        }
      }, {
        "range" : {
          "stock" : {
            "from" : 0,
            "to" : null,
            "include_lower" : false,
            "include_upper" : true
          }
        }
      }, {
        "range" : {
          "end" : {
            "from" : 1468836200000,
            "to" : null,
            "include_lower" : false,
            "include_upper" : true
          }
        }
      } ]
    }
  },
  "aggregations" : {
    "getLowStockItems" : {
      "terms" : {
        "field" : "item_id",
        "size" : 100,
        "order" : {
          "min_stock" : "asc"
        }
      },
      "aggregations" : {
        "min_stock" : {
          "min" : {
            "field" : "stock"
          }
        }
      }
    }
  }
}

 

POST nadeals-2016.07.18/default/_search

 

相关学习链接:

1,https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html

2,http://es.xiaoleilu.com/080_Structured_Search/10_compoundfilters.html

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics