Elastic Search - Failed to parse query - python

I am using python-elasticsearch client - elasticsearch.py and elastic search fails to parse query when I try to update a document using update_by_query method.
My update body is as follows:
{
'script': {
'inline': 'ctx._source.viewers += info',
'params': {
'info': {
'time': datetime.datetime(2017, 3, 7, 18, 8, 50),
'viewer': 'abc#xyz.com'
}
}
}
}
Elastic Search is called as follows::
update = es.update_by_query(index=index_el,
doc_type='1',
q='delivery_reference_id:' + str(cam_id) +'',
body=doc)
A sample value for cam_id is:
CAM_10_DATA_4_2017-03-07 18:02:07
Internally, the following query is formed::
http://127.0.0.1:9200/user_tracker/1/_update_by_query?q=delivery_reference_id%3ACAM_10_DATA_4_2017-03-07+18%3A02%3A07
The error received is as follows:
TransportError(400, 'search_phase_execution_exception', 'Failed to parse query [delivery_reference_id:CAM_10_DATA_4_2017-03-07 18:02:07]')
The full error log is as follows:
Traceback (most recent call last):
File "C:\Users\catch\AppData\Roaming\Python\Python34\site-packages\django\core\handlers\exception.py", line 42, in inner
response = get_response(request)
File "C:\Users\catch\AppData\Roaming\Python\Python34\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\catch\AppData\Roaming\Python\Python34\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\catch\AppData\Roaming\Python\Python34\site-packages\django\views\decorators\csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\catch\AppData\Roaming\Python\Python34\site-packages\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\rest_framework\views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "C:\Python34\lib\site-packages\rest_framework\views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "C:\Python34\lib\site-packages\rest_framework\views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "C:\Users\catch\PycharmProjects\myproject\myproj\apis\views.py", line 516, in get
viewer=viewer_email)
File "C:\Users\catch\PycharmProjects\myproject\myproj\apis\views.py", line 541, in update_track_info
doc=doc)
File "C:\Users\catch\PycharmProjects\myproject\myproj\apis\views.py", line 553, in es_update
body=doc)
File "C:\Python34\lib\site-packages\elasticsearch\client\utils.py", line 73, in _wrapped
return func(*args, params=params, **kwargs)
File "C:\Python34\lib\site-packages\elasticsearch\client\__init__.py", line 680, in update_by_query
doc_type, '_update_by_query'), params=params, body=body)
File "C:\Python34\lib\site-packages\elasticsearch\transport.py", line 318, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "C:\Python34\lib\site-packages\elasticsearch\connection\http_urllib3.py", line 128, in perform_request
self._raise_error(response.status, raw_data)
File "C:\Python34\lib\site-packages\elasticsearch\connection\base.py", line 122, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, 'search_phase_execution_exception', 'Failed to parse query [delivery_reference_id:CAM_10_DATA_4_2017-03-07 18:02:07]')
Would be nice if someone figured it out. Let me know if more info is needed.
Appreciate it. Thanks in advance.

I think your query syntax is not up to date. I had good results with the following syntax:
{
"query": {
"bool": {
"must": [
{ "match": { "MYFIELD": "myoldvalue" } }
]
}
},
"script": {
"inline": "ctx._source.MYFIELD = \"mynewvalue\"",
"lang": "painless"
}
}
HTH :)

Related

Probem with reading Json file in Youtube data API

I am trying to upload a video to YouTube using the upload_video method, but I am encountering a TypeError that says 'Object of type function is not JSON serializable.
Here is the code I am using:
def upload_video(title,description,tags,upload_year,uplaod_month,upload_day):
upload_date_time = datetime.datetime(upload_year,uplaod_month,upload_day, 8, 00, 0).isoformat() + 'Z'
print(f"this is a upload time {upload_date_time}")
request_body = {
'snippet': {
'categoryI': 19,
'title': title,
'description': description,
'tags': tags
},
'status': {
'privacyStatus': 'private',
'publishAt': upload_date_time,
'selfDeclaredMadeForKids': False,
},
'notifySubscribers': False
}
mediaFile = MediaFileUpload('output.MP4')
response_upload = service.videos().insert(
part='snippet,status',
body=request_body,
media_body=mediaFile
).execute()
This is the error message I am receiving:
Traceback (most recent call last): File "c:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\main.py", line 216, in <module>
upload_video(title,"#Shorts", ["motivation", "business", "luxury", "entrepreneurship", "success", "lifestyle", "inspiration", "wealth", "financial freedom", "investing", "mindset", "personal development", "self-improvement", "goals", "hustle", "ambition", "rich life", "luxury lifestyle", "luxury brand", "luxury travel", "luxury cars"],year,month,day) File "c:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\main.py", line 93, in upload_video
response_upload = service.videos().insert( File "C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\env\youtube\lib\site-packages\googleapiclient\discovery.py", line 1100, in method
headers, params, query, body = model.request( File "C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\env\youtube\lib\site-packages\googleapiclient\model.py", line 160, in request
body_value = self.serialize(body_value) File "C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\env\youtube\lib\site-packages\googleapiclient\model.py", line 273, in serialize
return json.dumps(body_value) File "C:\Users\Lukas\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj) File "C:\Users\Lukas\AppData\Local\Programs\Python\Python310\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True) File "C:\Users\Lukas\AppData\Local\Programs\Python\Python310\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0) File "C:\Users\Lukas\AppData\Local\Programs\Python\Python310\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type function is not JSON serializable

Python Web3 Ganache - Traceback error on BuildTransaction

I am going through the freeCodeCamp course on YouTube and have caught an error regarding when I run. As I am trying to build a transaction into Ganache. I see in Ganache logs that there is activity as well. First time posting, so let me know what other information should I provide!
The course: Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
The error that the terminal returns:
Traceback (most recent call last):
File "C:\Users\Justin\demos\web3_py_simple_storage\deploy.py",
line 60, in <module>
transaction = SimpleStorage.constructor().buildTransaction(
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\decorators.py", line 18, in _wrapper
return self.method(obj, *args, **kwargs)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\contract.py", line 684, in buildTransaction
return fill_transaction_defaults(self.web3, built_transaction)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\_utils\transactions.py", line 121, in fill_transaction_defaults
default_val = default_getter(web3, transaction)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\_utils\transactions.py", line 67, in <lambda>
'gas': lambda web3, tx: web3.eth.estimate_gas(tx),
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\eth.py", line 759, in estimate_gas
return self._estimate_gas(transaction, block_identifier)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\manager.py", line 197, in request_blocking
response = self._make_request(method, params)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\manager.py", line 150, in _make_request
return request_func(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\gas_price_strategy.py", line 90,
in middleware
return make_request(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\formatting.py", line 74, in apply_formatters
response = make_request(method, formatted_params)
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\attrdict.py", line 33, in middleware
response = make_request(method, params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\formatting.py", line 74, in apply_formatters
response = make_request(method, formatted_params)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\formatting.py", line 73, in apply_formatters
formatted_params = formatter(params)
File "cytoolz\functoolz.pyx", line 503, in cytoolz.functoolz.Compose.__call__
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\decorators.py", line 91, in wrapper
return ReturnType(result) # type: ignore
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\applicators.py", line 22, in apply_formatter_at_index
yield formatter(item)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\functional.py", line 45, in inner
return callback(fn(*args, **kwargs))
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\applicators.py", line 84, in apply_formatters_to_dict
yield key, formatters[key](item)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\eth_utils\applicators.py", line 72, in apply_formatter_if
return formatter(value)
File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "C:\Users\Justin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\web3\middleware\validation.py", line 57, in validate_chain_id
raise ValidationError(
web3.exceptions.ValidationError: The transaction declared chain ID 5777, but the connected node is on 1337
The Full Code that I used is below:
from solcx import compile_standard, install_solc
import json
from web3 import Web3
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
# Compile Our Solidity
print("Installing...")
install_solc("0.6.0")
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {
"*": [
"abi",
"metadata",
"evm.bytecode",
"evm.bytecode.sourceMap",
]
}
}
},
},
solc_version="0.6.0",
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)
# get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
"bytecode"
]["object"]
# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
# for connecting to ganache
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
chain_id = 5777
my_address = "0xf2580f5ddfFb89e69A12a7CbCa8CA175Df4cBe08"
private_key = "0x937073896304af4297e6bbb3a3c623689d48388aa8595058752fafb522b31a13"
# Create the contract in python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
print(SimpleStorage)
# Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)
# 1. Build a transaction
# 2. Sign a transaction
# 3. Send a transaction
transaction = SimpleStorage.constructor().buildTransaction(
{"chainId": chain_id, "from": my_address, "nonce": nonce}
)
print(transaction)
As of 5.25.0 of web3.py, we now need to add gasPrice to our transactions with a local Ganache chain. Adding "gasPrice": w3.eth.gas_price should fix your issue in the transactions.
Full Example:
transaction = SimpleStorage.constructor().buildTransaction(
{
"chainId": chain_id,
"gasPrice": w3.eth.gas_price,
"from": my_address,
"nonce": nonce,
}
)
Use the following line in .buildTransaction:
transaction = SimpleStorage.constructor().buildTransaction(
{'from': address, 'nonce':nonce, 'chainId':chain_id,'gas': 1728712,
'gasPrice': w3.toWei('21', 'gwei')})
And change the chain_id = 1337.
The transaction declared chain ID 5777, but the connected node is on 1337.
You have to change your chain_id:
chain_id = 5777❌
But use the one below
chain_id = 1337✔
I was having this exact same problem. Including "gasPrice": w3.eth.gas_price, solved it originally, but it came back.
After some tweaking, I found that casting chain_id (because I was getting that from .env as well) as an int solved my problems.
So the full code looked like this:
transaction = SimpleStorage.constructor().buildTransaction(
{
"chainId": int(chain_id),
"gasPrice": w3.eth.gas_price,
"from": my_address,
"nonce": nonce,
}
)

Error while uploading file on IPFS (TypeError: expected string or bytes-like object)

I am trying to upload a file on IPFS and retrieve it. The tutorial I am following uses the following approach:
import requests
import json
files = {
"file" : ("Congrats! You have uploaded this on IPFS."),
}
response_hash = requests.post("https://ipfs.infura.io:5001/api/v0/add", files = files)
p = response_hash.json()
hashed = p["Hash"]
print(p)
print(hashed)
params = (
("arg", hashed),
)
response = requests.post("https://ipfs.infura.io:5001/api/v0/block/get", params = params)
print(response.text)
However, I want to upload multiple data, preferably in the form of json arrays. I tried to modify it but I'm running into an error.
My code:
import requests
import json
example = {
"employees":[
{"name":"Shyam", "email":"shyamjaiswal#gmail.com"},
{"name":"Bob", "email":"bob32#gmail.com"},
{"name":"Jai", "email":"jai87#gmail.com"}
]}
response_hash = requests.post("https://ipfs.infura.io:5001/api/v0/add", files = example)
p = response_hash.json()
hashed = p["Hash"]
print(p)
print(hashed)
params = (
("arg", hashed),
)
response = requests.post("https://ipfs.infura.io:5001/api/v0/block/get", params = params)
print(response.text)
Error:
Traceback (most recent call last):
File "ipfs_v1.py", line 16, in <module>
response_hash = requests.post("https://ipfs.infura.io:5001/api/v0/add", files = example)
File "E:\Anaconda3\lib\site-packages\requests\api.py", line 119, in post
return request('post', url, data=data, json=json, **kwargs)
File "E:\Anaconda3\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "E:\Anaconda3\lib\site-packages\requests\sessions.py", line 516, in request
prep = self.prepare_request(req)
File "E:\Anaconda3\lib\site-packages\requests\sessions.py", line 459, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "E:\Anaconda3\lib\site-packages\requests\models.py", line 317, in prepare
self.prepare_body(data, files, json)
File "E:\Anaconda3\lib\site-packages\requests\models.py", line 505, in prepare_body
(body, content_type) = self._encode_files(files, data)
File "E:\Anaconda3\lib\site-packages\requests\models.py", line 166, in _encode_files
rf.make_multipart(content_type=ft)
File "E:\Anaconda3\lib\site-packages\urllib3\fields.py", line 268, in make_multipart
((u"name", self._name), (u"filename", self._filename))
File "E:\Anaconda3\lib\site-packages\urllib3\fields.py", line 225, in _render_parts
parts.append(self._render_part(name, value))
File "E:\Anaconda3\lib\site-packages\urllib3\fields.py", line 205, in _render_part
return self.header_formatter(name, value)
File "E:\Anaconda3\lib\site-packages\urllib3\fields.py", line 116, in format_header_param_html5
value = _replace_multiple(value, _HTML5_REPLACEMENTS)
File "E:\Anaconda3\lib\site-packages\urllib3\fields.py", line 89, in _replace_multiple
result = pattern.sub(replacer, value)
TypeError: expected string or bytes-like object
What am I doing wrong? How do I upload json arrays onto IPFS?
converted employee details as string
import requests
import json
files = {
"employees" : ( """{"name":"Shyam", "email":"shyamjaiswal#gmail.com"},
{"name":"Bob", "email":"bob32#gmail.com"},
{"name":"Jai", "email":"jai87#gmail.com"} """),
}
response_hash = requests.post("https://ipfs.infura.io:5001/api/v0/add", files = files)
p = response_hash.json()
hashed = p["Hash"]
print(p)
print(hashed)
params = (
("arg", hashed),
)
response = requests.post("https://ipfs.infura.io:5001/api/v0/block/get", params = params)
print(response.text)
output:
{'Name': 'employees', 'Hash': 'QmeGTapzFr36Bag6c1w4ZxiuJVM8wxDGMD7GFFmc7onV8c', 'Size': '161'}
QmeGTapzFr36Bag6c1w4ZxiuJVM8wxDGMD7GFFmc7onV8c
╗ {"name":"Shyam", "email":"shyamjaiswal#gmail.com"},
{"name":"Bob", "email":"bob32#gmail.com"},
{"name":"Jai", "email":"jai87#gmail.com"}

Create custom analyzer filter for a index in py-elasticsearch-dsl

i'm working with py-elasticsearch-dsl for my master, i'm creating a index of title documents in a corpus of turkish titles, and i need implements a custom lowercase analyzer for turkish language: https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-lowercase-tokenfilter.html#analysis-lowercase-tokenfilter
I'm trying do it with this:
turkish = analysis.token_filter('turkish_lowercase', type="lowercase", language="turkish")
turkish_lowercase = analyzer('turkish_lowercase',
type = "custom",
tokenizer="standard",
filter=["turkish_lowercase"],
)
class Document(DocType):
# title = Text()
query = Percolator(
analyzer=turkish_lowercase,
filter=turkish
) # query is a percolator
class Meta:
index = 'titles' # index name
doc_type = '_doc'
def save(self, **kwargs):
return super(Document, self).save(**kwargs)
But i'm getting this error:
python percolator.py  1 ↵  1736  17:37:54
PUT http://localhost:9200/title-index [status:400 request:0.004s]
Traceback (most recent call last):
File "percolator.py", line 55, in <module>
Document.init()
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch_dsl/document.py", line 161, in init
cls._doc_type.init(index, using)
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch_dsl/document.py", line 85, in init
self.mapping.save(index or self.index, using=using or self.using)
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch_dsl/mapping.py", line 116, in save
return index.save()
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch_dsl/index.py", line 219, in save
return self.create()
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch_dsl/index.py", line 203, in create
self.connection.indices.create(index=self._name, body=self.to_dict(), **kwargs)
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 76, in _wrapped
return func(*args, params=params, **kwargs)
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch/client/indices.py", line 91, in create
params=params, body=body)
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch/transport.py", line 314, in perform_request
status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 163, in perform_request
self._raise_error(response.status, raw_data)
File "/home/salahaddin/Proyectos/Works/seminer/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 125, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError: TransportError(400, 'illegal_argument_exception', 'Custom Analyzer [turkish_lowercase] failed to find filter under name [turkish_lowercase]')
So, what is the correct way to do this?
Thank you
For create a custom filter we can use token_filter:
turkish = analysis.token_filter('turkish_lowercase', type="lowercase", language="turkish")
We are creating a new lower_case filter for turkish language. Now, we need to create the analyzer:
turkish_lowercase = analyzer('turkish_lowercase',
type = "custom",
tokenizer="standard",
filter=[turkish],
)
We put turkish filter directly in the filter parameter, nothing more; we can review the result dictionary with the get_definition function either filter as analyzer.
Finally we apply that analyzer in our Document:
class Document(DocType):
title = Text(
analyzer=turkish_lowercase,
# filter=turkish
)
query = Percolator(
) # query is a percolator
class Meta:
index = 'titles' # index name
doc_type = '_doc'
def save(self, **kwargs):
return super(Document, self).save(**kwargs)
We will get the next result:
{
"titles":{
"aliases":{
},
"mappings":{
"_doc":{
"properties":{
"query":{
"type":"percolator"
},
"title":{
"type":"text",
"analyzer":"turkish_lowercase"
}
}
}
},
"settings":{
"index":{
"number_of_shards":"5",
"provided_name":"titles",
"analysis":{
"filter":{
"turkish_lowercase":{
"type":"lowercase",
"language":"turkish"
}
},
"analyzer":{
"turkish_lowercase":{
"filter":[
"turkish_lowercase"
],
"type":"custom",
"tokenizer":"standard"
}
}
},
"number_of_replicas":"1",
}
}
}
}

API python : neutron client common exceptions unauthorized

My neutronTest.py file
import getpass
from neutronclient.v2_0 import client
username = '#myUserName#'
password1 = getpass.getpass()
tenant_name = '#myTenantName#'
auth_url = 'https://keystone.#mydomain#.fr:5000/v3'
neutron = client.Client(username=username,
password = password1,
tenant_name = tenant_name,
auth_url = auth_url,
)
netw = neutron.list_networks()
print(netw)
Its gives me this Error :
The Error :
Traceback (most recent call last):
File "pythonTest.py", line 17, in <module>
netw=neutron.list_networks()
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 640, in list_networks
**_params)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 357, in list
for r in self._pagination(collection, path, **params):
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 372, in _pagination
res = self.get(path, params=params)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 342, in get
headers=headers, params=params)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 319, in retry_request
headers=headers, params=params)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 270, in do_request
resp, replybody = self.httpclient.do_request(action, method, body=body)
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/client.py", line 158, in do_request
self.authenticate_and_fetch_endpoint_url()
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/client.py", line 123, in authenticate_and_fetch_endpoint_url
self.authenticate()
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/client.py", line 237, in authenticate
self._authenticate_keystone()
File "/root/myEnv1/lib/python2.7/site-packages/neutronclient/client.py", line 218, in _authenticate_keystone
raise exceptions.Unauthorized(message=resp_body)
neutronclient.common.exceptions.Unauthorized: {"error": {"message": "The resource could not be found.", "code": 404, "title": "Not Found"}}
I think because I have a v3 keystone version, but I still don't know how to solve the problem.
Thank you for your help!

Categories

Resources