Elasticsearch jdbc sort by _id - elasticsearch

I want to make my results sortable by _id so I need to add
"_id" : {
"index" : "not_analyzed",
"store" : true
}
to my index, correct?
here is my script for jdbc feeder:
#!/bin/bash
#Verzeichnis von JDBC -> wichtig, anpassen!
export JDBC_IMPORTER_HOME=~/Downloads/elasticsearch-jdbc-1.6.0.0
bin=$JDBC_IMPORTER_HOME/bin
lib=$JDBC_IMPORTER_HOME/lib
echo '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://xxxxxxxxx",
"user" : "xxxx",
"password" : "xxxxxxx",
"index" : "xxxxxxxx",
"type" : "xxxxxx",
"sql" : "SELECT xxxxxxxxx"
}
}' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter
I added
"index_settings" : {
"_id" : {
"index" : "not_analyzed",
"store" : true
}
}
after
"password" : "xxxxxxx",
"index" : "xxxxxxxx",
but it doesn't work
where do I add this setting?

Related

Es update giving bad request

I am trying to update the following document:
$ curl http://192.168.0.108:9200/customer/customer/AVGbTCQ2XioLLLZULBAD?pretty
{
"_index" : "customer",
"_type" : "customer",
"_id" : "AVGbTCQ2XioLLLZULBAD",
"_version" : 15,
"found" : true,
"_source":{"age":0,"n":"Abhishek Gupta","id":"AVGbTCQ2XioLLLZULBAD"}
}
According to update API my update request is:
$ curl -XPOST http://192.168.0.108:9200/customer/customer/AVGbTCQ2XioLLLZULBAD/_update -d '{
> "script": {
> "inline": "ctx._source.n = name",
> "params": {
> "name": "Elas"
> }
> }
> }'
{"error":"ActionRequestValidationException[Validation Failed: 1: script or doc is missing;]","status":400}
Why I am getting bad request?
Es version details:
$ curl http://192.168.0.108:9200/
{
"status" : 200,
"name" : "Vance Astro",
"cluster_name" : "dexter-elasticsearch",
"version" : {
"number" : "1.7.1",
"build_hash" : "b88f43fc40b0bcd7f173a1f9ee2e97816de80b19",
"build_timestamp" : "2015-07-29T09:54:16Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"
}
Scripted updated in ES 1.7.1 is slightly different than in ES 2.x, i.e. there is no inline parameter like in ES 2.x, instead you write it like this:
curl -XPOST http://192.168.0.108:9200/customer/customer/AVGbTCQ2XioLLLZULBAD/_update -d '{
"script": "ctx._source.n = name",
"params": {
"name": "Elas"
}
}'

Elastic search csv river module not working

I am trying to index csv file in elasticsearch
curl -XPUT localhost:9200/_river/my_csv_river/_meta -d '
{
"type" : "csv",
"csv_file" : {
"folder" : "/tmp",
"filename_pattern" : ".*\\.csv$",
"first_line_is_header" : "true",
"field_separator" : ",",
"field_id" : "_id"
},
"index" : {
"index" : "my_csv_data_1",
"type" : "csv_type_1",
"bulk_size" : 100,
"bulk_threshold" : 10
}
}'
after indexing while searching http://localhost:9200/my_csv_data_1/_search
got
{
error: "IndexMissingException[[my_csv_data_1] missing]",
status: 404
}
any thoughts or i missed any thing?

Elasticsearch:how to use elasticsearch-river-jdbc to keep in sync(MySql)

Now i am working with elasticsearch-river-jdbc.When i update Mysql database,i want my elasitcsearchdata will update(automatic).When i created a river,this is my code:
curl -XPUT '127.0.0.1:9200/_river/my_jdbc_river/_meta' -d '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://localhost:3306/myapp_development",
"user" : "root",
"password" : "",
"sql" : "select * from users",
"autocommit" : "true"
}
}'
But when i update mysql,nothing in elasticsearch data changes.
So what is my wrong??
Simply add 'schedule' as documented here:
elasticsearch-river-jdbc#time-scheduled-execution-of-jdbc-river
{
"type" : "jdbc",
"schedule" : "0 0-59 0-23 ? * *",
"jdbc" : [ {
"url" : "jdbc:mysql://localhost:3306/ZZZZ",
"user" : "root",
"password" : "ZZZ",
"sql" : "Select …"
}]
}
(This one will get updates every minute)

Elasticsearch river - no _meta document found after 5 attempts

I am using elasticsearch version 1.3.0. when I create a river using wikipedia plugin version 2.3.0 as thus
PUT _river/my_river/_meta -d
{
"type" : "wikipedia",
"wikipedia" : {
"url" : "http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2"
},
"index" : {
"index" : "wikipedia",
"type" : "wiki",
"bulk_size" : 1000,
"max_concurrent_bulk" : 3
}
}
the server responds with this message
{
"_index": "_river",
"_type": "my_river",
"_id": "_meta -d",
"_version": 1,
"created": true
}
however, I don't see the wikipedia documents when I run a search. also, when I restart my server I get river-routing no _meta document found after 5 attempts
Remove the -d at the end as it creates a document named _meta -d and not _meta.
PUT _river/my_river/_meta
{
"type" : "wikipedia",
"wikipedia" : {
"url" : "http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2"
},
"index" : {
"index" : "wikipedia",
"type" : "wiki",
"bulk_size" : 1000,
"max_concurrent_bulk" : 3
}
}

Specify Routing on Index Alias's Term Lookup Filter

I am using Logstash, ElasticSearch and Kibana to allow multiple users to log in and view the log data they have forwarded. I have created index aliases for each user. These restrict their results to contain only their own data.
I'd like to assign users to groups, and allow users to view data for the computers in their group. I created a parent-child relationship between the groups and the users, and I created a term lookup filter on the alias.
My problem is, I receive a RoutingMissingException when I try to apply the alias.
Is there a way to specify the routing for the term lookup filter? How can I lookup terms on a parent document?
I posted the mapping and alias below, but a full gist recreation is available at this link.
curl -XPUT 'http://localhost:9200/accesscontrol/' -d '{
"mappings" : {
"group" : {
"properties" : {
"name" : { "type" : "string" },
"hosts" : { "type" : "string" }
}
},
"user" : {
"_parent" : { "type" : "group" },
"_routing" : { "required" : true, "path" : "group_id" },
"properties" : {
"name" : { "type" : "string" },
"group_id" : { "type" : "string" }
}
}
}
}'
# Create the logstash alias for cvializ
curl -XPOST 'http://localhost:9200/_aliases' -d '
{
"actions" : [
{ "remove" : { "index" : "logstash-2014.04.25", "alias" : "cvializ-logstash-2014.04.25" } },
{
"add" : {
"index" : "logstash-2014.04.25",
"alias" : "cvializ-logstash-2014.04.25",
"routing" : "intern",
"filter": {
"terms" : {
"host" : {
"index" : "accesscontrol",
"type" : "user",
"id" : "cvializ",
"path" : "group.hosts"
},
"_cache_key" : "cvializ_hosts"
}
}
}
}
]
}'
In attempting to find a workaround for this error, I submitted a bug to the ElasticSearch team, and received an answer from them. It was a bug in ElasticSearch where the filter is applied before the dynamic mapping, causing some erroneous output. I've included their workaround below:
PUT /accesscontrol/group/admin
{
"name" : "admin",
"hosts" : ["computer1","computer2","computer3"]
}
PUT /_template/admin_group
{
"template" : "logstash-*",
"aliases" : {
"template-admin-{index}" : {
"filter" : {
"terms" : {
"host" : {
"index" : "accesscontrol",
"type" : "group",
"id" : "admin",
"path" : "hosts"
}
}
}
}
},
"mappings": {
"example" : {
"properties": {
"host" : {
"type" : "string"
}
}
}
}
}
POST /logstash-2014.05.09/example/1
{
"message":"my sample data",
"#version":"1",
"#timestamp":"2014-05-09T16:25:45.613Z",
"type":"example",
"host":"computer1"
}
GET /template-admin-logstash-2014.05.09/_search

Resources