Search code examples
elasticsearchlogstashopensearch

Logstash opensearch output no getting document_id


I am trying to transfer data between two opensearch instances using:

input {
    opensearch {
        hosts =>  ["http://192.168.1.245:8443"]
        index =>  "crawl"
        query =>  '{ "query": { "match_all": {}} }'
    }
}

output {
  opensearch {
    hosts => ["http://192.168.1.245:9200"]
    index => "crawl"
    document_id => "%{[id]}"
    doc_as_upsert => true 
  }
  stdout { codec => rubydebug { metadata => true } }
}

The problem I have is that it is not inserting the the input document_id into the output document_id:

I tried:

document_id => "%{[id]}"
document_id => "%{id}"
document_id => "%{[_id]}"
document_id => "%{_id}"
document_id => "%{[document_id]}"
document_id => "%{document_id}"
document_id => "%{[metadata][id]}"

it saves it into the index as the lookup:

"_index": "crawl",
"_id": "%{document_id}",
"_score": 1.0,

Anybody have some ideas on how to get this to work?


Solution

  • Based on the advise given by Val I managed to get it to work with the following:

    input {
        opensearch {
            hosts =>  ["http://192.168.1.245:8443"]
            index =>  "crawl"
            query =>  '{ "query": { "match_all": {}} }'
            docinfo => true <----
            docinfo_target => "[@metadata][doc]" <----
        }
    }
    
    output {
      opensearch {
        hosts => ["http://192.168.1.245:9200"]
        index => "crawl"
        document_id => "%{[@metadata][doc][_id]}" <----
        doc_as_upsert => true 
      }
      stdout { codec => rubydebug { metadata => true } }
    }