Skip to content

Instantly share code, notes, and snippets.

@jpoth
Last active January 3, 2016 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpoth/8406466 to your computer and use it in GitHub Desktop.
Save jpoth/8406466 to your computer and use it in GitHub Desktop.
elasticsearch -parent/child example
curl localhost:9200/_river/person/_mapping -d '{
"person":{
"properties:{
"person_id":{"type":"integer"},
"name":{"type":"string"}
}
}
}'
curl localhost:9200/_river/person/_meta -d '{
"type":"jdbc",
"jdbc": {
"driver":"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"url":"jdbc:sqlserver://127.0.0.1:1433;databaseName=blogcontext",
"user":"sa","password":"password",
"sql":"select person_id as _id, name from person",
"poll":"30s"
},
"index": {
"index":"library",
"type":"person",
"bulk_size":500
}}'
curl -XPUT 'localhost:9200/_river/work/_mapping' -d '{
"work":{
"_parent":{"type": "person"},
"properties":{
"person_id":{"type" : "integer", "index" : "not_analyzed"},
"name":{"type" : "string"},
"genre":{"type" : "string"},
"publisher":{"type" : "string"}
}
}
}'
curl -XPUT localhost:9200/_river/work/_meta -d '{
"type":"jdbc",
"jdbc": {
"driver":"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"url":"jdbc:sqlserver://127.0.0.1:1433;databaseName=blogcontext",
"user":"sa","password":"password",
"sql":"select person_id as _parent,name,genre,publisher from work",
"poll":"30s"
},
"index": {
"index":"library",
"type":"work",
"bulk_size":500
}}'
@dqduc
Copy link

dqduc commented Jan 14, 2014

Remove both commands "..._river/.../_mapping", run this first, then run your ".._river/.../_meta" after that

curl -XPOST 'http://localhost:9200/library' -d '{
    "settings" : {
        "number_of_shards" : 1,
        "number_of_replicas" : 0
    },
    "mappings" : {
      "person" : {
        "properties" : {
          "person_id":{"type":"integer"},
          "name":{"type":"string"}
        }
      },
      "work" : {
        "_parent" : {
          "type" : "person"
        },
        "properties" : {
          "person_id":{"type" : "integer", "index" : "not_analyzed"},
"name":{"type" : "string"},
"genre":{"type" : "string"},
"publisher":{"type" : "string"}
        }
      }
    }
}' 

@jpoth
Copy link
Author

jpoth commented Jan 14, 2014

curl -XPOST 'http://localhost:9200/library' -d '{
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
},
"mappings" : {
"person" : {
"properties" : {
"person_id":{"type":"integer"},
"name":{"type":"string"}
}
},
"work" : {
"_parent" : {
"type" : "person"
},
"properties" : {
"person_id":{"type" : "integer", "index" : "not_analyzed"},
"name":{"type" : "string"},
"genre":{"type" : "string"},
"publisher":{"type" : "string"}
}
}
}
}'

curl -XPUT localhost:9200/_river/person/_meta -d '{

"type":"jdbc",
"jdbc": {
"driver":"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"index":"library",
"url":"jdbc:sqlserver://127.0.0.1:1433;databaseName=blogcontext",
"user":"sa","password":"password",
"sql":"select person_id as _id, name from person",
"poll":"30s"
},
"index": {
"index":"library",
"type":"person",
"bulk_size":500
}}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 388 100 73 100 315 146 630 --:--:-- --:--:-- --:--:-- 649{"ok":true,"_index":"_river","_type":"person","_id":"_meta","_version":1}

curl -XPUT localhost:9200/_river/work/_meta -d '{

"type":"jdbc",
"jdbc": {
"sql":"s> elect person"_id as _parendt,name,genrre,publisheri from work"v,
er":"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"url":"jdbc:sqlserver://127.0.0.1:1433;databaseName=blogcontext",
"user":"sa","password":"password",
"sql":"select person_id as _parent,name,genre,publisher from work",
"poll":"30s"
},
"index": {
"index":"library",
"type":"work",
"bulk_size":500
}}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 401 100 71 100 330 1543 7173 --:--:-- --:--:-- --:--:-- 7173{"ok":true,"_index":"_river","_type":"work","_id":"_meta","_version":1}

@dqduc
Copy link

dqduc commented Jan 16, 2014

river is wrong endpoint, it should be _river, so the command to create rivers will look like:

curl -XDELETE "http://localhost:9200/_river/" 

curl -XPUT localhost:9200/_river/person/meta -d '{

"type":"jdbc",
"jdbc": {
"driver":"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"index":"library",
"url":"jdbc:sqlserver://127.0.0.1:1433;databaseName=blogcontext",
"user":"sa","password":"password",
"sql":"select person_id as _id, name from person",
"poll":"30s"
},
"index": {
"index":"library",
"type":"person",
"bulksize":500
}}'

curl -XPUT localhost:9200/_river/work/meta -d '{
"type":"jdbc",
"jdbc": {
"driver":"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"index":"library",
"url":"jdbc:sqlserver://127.0.0.1:1433;databaseName=blogcontext",
"user":"sa","password":"password",
"sql":"select personid as _parent,name,genre,publisher from work",
"poll":"30s"
},
"index": {
"index":"library",
"type":"work",
"bulksize":500
}}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment