本文整理匯總了Python中elasticsearch_dsl.Index方法的典型用法代碼示例。如果您正苦於以下問題:Python elasticsearch_dsl.Index方法的具體用法?Python elasticsearch_dsl.Index怎麽用?Python elasticsearch_dsl.Index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類elasticsearch_dsl
的用法示例。
在下文中一共展示了elasticsearch_dsl.Index方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: applyConfig
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def applyConfig(self):
try:
print("Connecting to '%s', index '%s'" % (self.confESHost, self.confESIndex))
self.es = connections.create_connection(hosts=[self.confESHost])
self.idx = Index(self.confESIndex)
self.idx.doc_type(DocHTTPRequestResponse)
if self.idx.exists():
self.idx.open()
else:
self.idx.create()
self.callbacks.saveExtensionSetting("elasticburp.host", self.confESHost)
self.callbacks.saveExtensionSetting("elasticburp.index", self.confESIndex)
self.callbacks.saveExtensionSetting("elasticburp.tools", str(self.confBurpTools))
self.callbacks.saveExtensionSetting("elasticburp.onlyresp", str(int(self.confBurpOnlyResp)))
except Exception as e:
JOptionPane.showMessageDialog(self.panel, "<html><p style='width: 300px'>Error while initializing ElasticSearch: %s</p></html>" % (str(e)), "Error", JOptionPane.ERROR_MESSAGE)
### ITab ###
示例2: test_dynamic_resource
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def test_dynamic_resource(self):
Index('test-1').delete(ignore=404)
Index('test-2').delete(ignore=404)
docs1 = [
dict(idx='test-1', body='something'),
dict(idx='test-1', body='else'),
]
docs2 = [
dict(idx='test-2', body='abra'),
dict(idx='test-2', body='ca'),
dict(idx='test-2', body='dabra'),
]
self.sc.parallelize(docs1 + docs2).saveToEs(resource_write='{idx}/docs')
self.assertEqual(self.sc.esRDD('test-1/docs').count(), 2)
self.assertEqual(self.sc.esRDD('test-2/docs').count(), 3)
self.assertEqual(
set(d['body'] for d in self.sc.esRDD('test-1/docs').loads().collectAsMap().values()),
set(d['body'] for d in docs1)
)
示例3: init
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def init(cls, index_prefix, index_settings=None, skip_template_init=False):
"""
Create the index template, and populate LogEntry's mapping and index settings.
"""
wildcard_index = Index(name=index_prefix + "*")
wildcard_index.settings(**(index_settings or {}))
wildcard_index.document(cls)
cls._index = wildcard_index
cls._index_prefix = index_prefix
if not skip_template_init:
cls.create_or_update_template()
# Since the elasticsearch-dsl API requires the document's index being defined as an inner class at the class level,
# this function needs to be called first before being able to call `save`.
cls._initialized = True
示例4: test_index_template_works
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def test_index_template_works(write_client):
it = IndexTemplate('test-template', 'test-*')
it.document(Post)
it.settings(number_of_replicas=0, number_of_shards=1)
it.save()
i = Index('test-blog')
i.create()
assert {
'test-blog': {
'mappings': {
'properties': {
'title': {'type': 'text', 'analyzer': 'my_analyzer'},
'published_from': {'type': 'date'},
}
}
}
} == write_client.indices.get_mapping(index='test-blog')
示例5: test_multiple_indices_with_same_doc_type_work
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def test_multiple_indices_with_same_doc_type_work(write_client):
i1 = Index('test-index-1', using=write_client)
i2 = Index('test-index-2', using=write_client)
for i in (i1, i2):
i.document(Post)
i.create()
for i in ('test-index-1', 'test-index-2'):
settings = write_client.indices.get_settings(index=i)
assert settings[i]['settings']['index']['analysis'] == {
'analyzer': {
'my_analyzer': {
'type': 'custom',
'tokenizer': 'keyword'
}
}
}
示例6: _create_index
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def _create_index(self):
# https://github.com/csirtgadgets/massive-octo-spice/blob/develop/elasticsearch/observables.json
# http://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.Elasticsearch.bulk
# every time we check it does a HEAD req
if self.last_index_value and (datetime.utcnow() - self.last_index_check) < timedelta(minutes=2):
return self.last_index_value
idx = self._current_index()
if not self.handle.indices.exists(idx):
index = Index(idx)
index.aliases(live={})
index.doc_type(Indicator)
index.settings(max_result_window=WINDOW_LIMIT)
index.create()
self.handle.indices.flush(idx)
self.last_index_check = datetime.utcnow()
self.last_index_value = idx
return idx
示例7: update_popularity_metadata
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def update_popularity_metadata(distribution: Distribution):
if not Index(SeriesQuery._doc_type.index).exists():
return
series = SeriesRepository.get_available_series(distribution=distribution)
series_ids = series.values_list('identifier', flat=True)
if not series_ids:
return
for meta_key, days in KEY_DAYS_PAIRS:
s = SeriesQuery.search()
if days:
s = s.filter('range', timestamp={'gte': f'now-{days}d/d'})
buckets = {serie_id: get_serie_filter(serie_id) for serie_id in series_ids}
agg_result = popularity_aggregation(s, buckets)
update_series_popularity_metadata(agg_result, meta_key, series)
示例8: tseries_index
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def tseries_index(name: str) -> Index:
index = Index(name)
# Fija el límite superior de valores en una respuesta. Si filtramos por serie, sería
# la cantidad de valores máximas que puede tener una única serie temporal.
index.settings(max_result_window=settings.MAX_SERIES_VALUES)
if not index.exists():
index.create()
index.put_mapping(doc_type=settings.TS_DOC_TYPE,
body=constants.MAPPING)
index.save()
# Actualizo el mapping
mapping = index.get_mapping(doc_type=settings.TS_DOC_TYPE)
doc_properties = mapping[name]['mappings'][settings.TS_DOC_TYPE]['properties']
if not doc_properties.get('raw_value'):
index.put_mapping(doc_type=settings.TS_DOC_TYPE,
body=constants.MAPPING)
return index
示例9: add_analyzer
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def add_analyzer(index: Index):
"""Agrega un nuevo analyzer al índice, disponible para ser usado
en todos sus fields. El analyzer aplica lower case + ascii fold:
quita acentos y uso de ñ, entre otros, para permitir búsqueda de
texto en español
"""
synonyms = list(Synonym.objects.values_list('terms', flat=True))
filters = ['lowercase', 'asciifolding']
if synonyms:
filters.append(token_filter(constants.SYNONYM_FILTER,
type='synonym',
synonyms=synonyms))
index.analyzer(
analyzer(constants.ANALYZER,
tokenizer='standard',
filter=filters)
)
示例10: __init__
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def __init__(self, name='qb', similarity='default', bm25_b=None, bm25_k1=None):
self.name = name
self.ix = Index(self.name)
self.answer_doc = create_doctype(self.name, similarity)
if bm25_b is None:
bm25_b = .75
if bm25_k1 is None:
bm25_k1 = 1.2
self.bm25_b = bm25_b
self.bm25_k1 = bm25_k1
示例11: build_large_docs
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def build_large_docs(self, documents: Dict[str, str], use_wiki=True, use_qb=True, rebuild_index=False):
if rebuild_index or bool(int(os.getenv('QB_REBUILD_INDEX', 0))):
log.info(f'Deleting index: {self.name}')
self.delete()
if self.exists():
log.info(f'Index {self.name} exists')
else:
log.info(f'Index {self.name} does not exist')
self.init()
wiki_lookup = Wikipedia()
log.info('Indexing questions and corresponding wikipedia pages as large docs...')
for page in tqdm.tqdm(documents):
if use_wiki and page in wiki_lookup:
wiki_content = wiki_lookup[page].text
else:
wiki_content = ''
if use_qb:
qb_content = documents[page]
else:
qb_content = ''
answer = self.answer_doc(
page=page,
wiki_content=wiki_content, qb_content=qb_content
)
answer.save(index=self.name)
示例12: build_many_docs
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def build_many_docs(self, pages, documents, use_wiki=True, use_qb=True, rebuild_index=False):
if rebuild_index or bool(int(os.getenv('QB_REBUILD_INDEX', 0))):
log.info(f'Deleting index: {self.name}')
self.delete()
if self.exists():
log.info(f'Index {self.name} exists')
else:
log.info(f'Index {self.name} does not exist')
self.init()
log.info('Indexing questions and corresponding pages as many docs...')
if use_qb:
log.info('Indexing questions...')
for page, doc in tqdm.tqdm(documents):
self.answer_doc(page=page, qb_content=doc).save()
if use_wiki:
log.info('Indexing wikipedia...')
wiki_lookup = Wikipedia()
for page in tqdm.tqdm(pages):
if page in wiki_lookup:
content = word_tokenize(wiki_lookup[page].text)
for i in range(0, len(content), 200):
chunked_content = content[i:i + 200]
if len(chunked_content) > 0:
self.answer_doc(page=page, wiki_content=' '.join(chunked_content)).save()
示例13: createMenuItems
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def createMenuItems(self, invocation):
menuItems = list()
selectedMsgs = invocation.getSelectedMessages()
if selectedMsgs != None and len(selectedMsgs) >= 1:
menuItems.append(JMenuItem("Add to ElasticSearch Index", actionPerformed=self.genAddToES(selectedMsgs, invocation.getInputEvent().getComponent())))
return menuItems
示例14: mitm_request
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def mitm_request(self, data):
# Initialize ES connection and index
res = connections.create_connection(hosts=[args.elasticsearch])
idx = Index(args.index)
idx.doc_type(DocHTTPRequestResponse)
try:
DocHTTPRequestResponse.init()
idx.create()
except:
pass
r = HTTPRequest(data)
# determine url
if self.is_connect:
scheme = "https"
else:
scheme = "http"
url = scheme + "://" + self.hostname
if scheme == "http" and int(self.port) != 80 or scheme == "https" and int(self.port) != 443:
url += ":" + str(self.port)
url += self.path
if args.verbose:
print(url)
self.doc = DocHTTPRequestResponse(host=self.hostname, port=int(self.port), protocol=scheme)
self.doc.meta.index = args.index
self.doc.request.url = url
self.doc.request.requestline = r.requestline
self.doc.request.method = r.command
self.doc.host = self.hostname
self.doc.port = int(self.port)
self.doc.protocol = scheme
return data
示例15: es_index_mapping
# 需要導入模塊: import elasticsearch_dsl [as 別名]
# 或者: from elasticsearch_dsl import Index [as 別名]
def es_index_mapping(index_name, doc_type, force=False):
# 創建索引
index = Index(index_name)
index.doc_type(doc_type)
if not index.exists():
index.create()
else:
if force:
index.upgrade()