ElasticSearch – Get only matching nested objects with All Top level fields in search response

If you’re ok with having all root fields except the nested one and then only the matching inner hits in the nested field, then we can re-use the previous answer like this by specifying a slightly more involved source filtering parameter: { “_source”: { “includes”: [ “*” ], “excludes”: [ “users” ] }, “query”: { … Read more

elasticsearch – querying multiple indexes is possible?

This is quite easy within Elasticsearch itself! Anytime you would specify an index, you can separate additional indices by comma. curl -XGET ‘http://localhost:9200/index1,index2/_search?q=yourQueryHere’ You can also search all indices with _all. curl -XGET ‘http://localhost:9200/_all/_search?q=yourQueryHere’ Here’s some helpful documentation from elasticsearch’s website. This site has TONS of info, but it is a bit difficult to find … Read more

low disk watermark [??%] exceeded on

If you like me have a lot of disk you can tune the watermark setting and use byte values instead of percentages: NB! Use either percentage values or byte values. You cannot mix the usage of percentage/ratio values and byte values within the watermark settings. Either all values are set to percentage/ratio values, or all … Read more

ElasticSearch: Unassigned Shards, how to fix?

By default, Elasticsearch will re-assign shards to nodes dynamically. However, if you’ve disabled shard allocation (perhaps you did a rolling restart and forgot to re-enable it), you can re-enable shard allocation. # v0.90.x and earlier curl -XPUT ‘localhost:9200/_settings’ -d ‘{ “index.routing.allocation.disable_allocation”: false }’ # v1.0+ curl -XPUT ‘localhost:9200/_cluster/settings’ -d ‘{ “transient” : { “cluster.routing.allocation.enable” : … Read more

How to iterate through a nested array in elasticsearch with filter script?

Nested documents are powerful because you retain certain attribute connections but there’s the downside of not being able to iterate over them as discussed here. With that being said you could flatten the users attributes using the copy_to feature like so: PUT my-index-000001 { “mappings”: { “properties”: { “user__first_flattened”: { “type”: “keyword” }, “user”: { … Read more

Elasticsearch, Tire, and Nested queries / associations with ActiveRecord

The support for ActiveRecord associations in Tire is working, but requires couple of tweaks inside your application. There’s no question the library should do better job here, and in the future it certainly will. That said, here is a full-fledged example of Tire configuration to work with Rails’ associations in elasticsearch: active_record_associations.rb Let me highlight … Read more