<commit_before>#!/usr/bin/env python

import pprint

from elasticsearch import Elasticsearch

'''Inside ipython:
[(r['_score'], r['_source']['Header']['En'], r['_source']['UnitTypeDesc'])for r in es.mlt(index='bhp10', doc_type='places', id=71433, mlt_fields=related_fields, search_types=['places','personalities','photoUnits','familyNames'], search_size=40)['hits']['hits']]
'''

def get_related(es, doc_id, index, doc_type, mlt_fields, target_collections, limit):
    return [(r['_score'], r['_source']['Header']['En'], r['_source']['UnitTypeDesc'])for r in es.mlt(index=index, doc_type=doc_type, id=doc_id, mlt_fields=mlt_fields, search_types=target_collections, search_size=limit)['hits']['hits']]

if __name__ == '__main__':
    es = Elasticsearch()<commit_msg>Add ES search example, similar to Mongo related FTS<commit_after>#!/usr/bin/env python

import pprint

from elasticsearch import Elasticsearch

'''Inside ipython:
[(r['_score'], r['_source']['Header']['En'], r['_source']['UnitTypeDesc'])for r in es.mlt(index='bhp10', doc_type='places', id=71433, mlt_fields=related_fields, search_types=['places','personalities','photoUnits','familyNames'], search_size=40)['hits']['hits']]
'''

'''Try with search:
es.search(doc_type='', size=1, q='UnitText1.En:Einstein')
Or even better:
[(r['_score'], r['_source']['Header']['En'], r['_source']['UnitTypeDesc'], r['_id'])for r in es.search(doc_type=['places'], size=40, q='UnitText1.En:Albert Einstein')['hits']['hits']]
'''

def get_related(es, doc_id, index, doc_type, mlt_fields, target_collections, limit):
    return [(r['_score'], r['_source']['Header']['En'], r['_source']['UnitTypeDesc'])for r in es.mlt(index=index, doc_type=doc_type, id=doc_id, mlt_fields=mlt_fields, search_types=target_collections, search_size=limit)['hits']['hits']]

if __name__ == '__main__':
    es = Elasticsearch()
{'fraction_non_alphanumeric': 0.20961642355483523, 'fraction_numerical': 0.01242571582928147, 'mean_word_length': 10.156626506024097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2247933', 'n_tokens_mistral': 670, 'n_tokens_neox': 650, 'n_words': 118}