Why elasticsearch request body query analyzer not working? - elasticsearch

When I use the simplest get query ( /index/_search?q=北京 ) , the results seems normal. But when I use the request body query , like below:
{
'query': {
'query_string':{
'query': '北京'
}
}
}
It seems elasticsearch not use analyzer I specific by the mapping setting, even I add the analyzer setting in the query body.
Can anyone help me find out what's wrong? Thank you.

Related

Match query doesn't return the result

i am new to ES. I am using the ES 7.2 and i am making this query from Kibana. I write the below query to get all the documents who has "11" in field STATUS.
GET /index1/_search
{
"query":{
"match" : {
"STATUS":"11"
}
}
}
But the result includes as well the documents with STATUS other than 11. What do i do wrong? I want that the query returns just the docs with STATUS 11.
Try not to let more than one space between the GET /in... and your query.
Instead of:
GET ...
{
your query
}
Do this:
GET ...
{
your query
}
If you run it like you have it now, it only will run the GET petition, which is like you were telling it "Bring me everything".
Hope this is helpful! :D

need help for Odata query to get 'Configuration' value (3) for 'AppParamConfigs's "Name":"XYZ",

with below Odata query
https://localhost:8080/odata/AppParams(1F2EE62A-8273-E811-81C6-185E0F9B6D7D)?$expand=AppParamConfigs
I'm getting all the AppParamConfigs like below,
{
"#odata.context":"https://localhost:8080/odata/$metadata#AppParams/$entity","Id":"1f2ee62a-8273-e811-81c6-185e0f9b6d7d","Name":"A","AppParamConfigs":[
{
"Id":"722fe62a-8273-e811-81c6-185e0f9b6d7d","Name":"ABC","Configuration":"2"
},{
"Id":"732fe62a-8273-e811-81c6-185e0f9b6d7d","Name":"XYZ","Configuration":"3"
}
]
}
Now I would like to get the Configuration value (3) for "Name":"XYZ" ?
I tried below, but not working
https://localhost:8080/odata/AppParams(1F2EE62A-8273-E811-81C6-185E0F9B6D7D)?$expand=AppParamConfigs($select=Name%20eq%20XYZ)
Try
https://localhost:8080/odata/AppParams(1F2EE62A-8273-E811-81C6-185E0F9B6D7D)?$expand=AppParamConfigs&$filter=Name eq 'XYZ'&$select=Configuration
You have to filter first then select.

Elastic search: Delete by query isn't working

Introduction
I'm using Elastic Search (v5.x) and trying to delete documents, by query.
My index called "data". The documents are stored in hierarchic structure. Documents URL built in this pattern:
https://server.ip/data/{userid}/{document-id}
So, let's say the user-id '1' have two documents stored ('1', '2'). So, their direct URL will be:
https://server.ip/data/1/1
https://server.ip/data/1/2
Target
Now, what I'm trying to do is to delete the user from the system (the user and his stored documents).
The only way that worked for me is to send HTTP DELETE request for each document URL. Like this:
DELETE https://server.ip/data/1/1
DELETE https://server.ip/data/1/2
This is working. But, in this solution I have to call delete multiple times. I want to delete all the documents in one call. So, this solution is rejected.
My first try was to send HTTP DELETE request to
https://server.ip/data/1
Unfortently, it's not working (error code 400).
My second try was to use the _delete_by_query function. Each document that I'm stored is containing the UserId field, which contain the UserId. So, I tried to make a delete query for removing all the documents, in 'data' index, that containing the field with the value 1 ('UserId'==1)
POST https://server.ip/data/_delete_by_query
{
"query":{
"match":{
"UserId":"1"
}
}
}
This also not working. The response was HTTP Error Code 400 with this body:
{
"error":{
"root_cause":[
{
"type":"invalid_type_name_exception",
"reason":"Document mapping type name can't start with '_'"
}
],
"type":"invalid_type_name_exception",
"reason":"Document mapping type name can't start with '_'"
},
"status":400
}
Do you know how to solve those problems? Maybe do you have alternative solution?
Thank you!
I assume you've got your document_type defined in your logstash conf something like this within your output>elasticsearch:
output {
elasticsearch {
index => "1"
document_type => "1type"
hosts => "localhost"
}
stdout {
codec => rubydebug
}
}
Hence you could simply delete all the documents which has the same type:
curl -XDELETE https://server.ip/data/1/1type
OR try something like this if you're willing to use delete by query:
POST https://server.ip/data/_delete_by_query?UserId=1
{
"query": {
"match_all": {}
}
}
This could be an absolute gem of a source. Hope it helps!

Elasticsearch not returning results for aggregate query but returns results for other queries

hi I'm new to elastic search and when i try a aggregate query it is not returning any results.
http://localhost:9200/contract/_search?search_type=count
{
"aggregations": {
"status_cons": {
"terms": {
"field": "data.policyStatus",
"size": 0
}
}
}
}
Note: this is just one of the queries that i had tried ,I have give size as 0 with the query and remove the search type ,added a query term with match_all etc
found out this is a bug in the head plugin. GET method doesn't work using the head plugin.
Related dicussion :Different result when using GET/POST in elastic search
no results for aggregation
it worked at last !!!!! .please use a POST request when using the elastic search head plugin it .

How about using body and GET parameters at the same time?

I am passing here some parameters via get to limit query result and also query_string is passed in url. Although, I am also giving request body to filter results.
curl -XGET 'http://localhost:9200/books/fantasy/_search?from=0&size=10&q=%2A' -d '{
"query":{
"filtered":{
"filter":{
"exists":{
"field":"speacial.ean"
}
}
}
}
}'
I just want to check is this approach okay? is there any downsides doing it like this? Or should I pass any parameters in url when body is used?
This seems to work, but is it bad practice?
GET requests are not supposed to use a body ( more information on this here). While curl might convert your GET requests with a body to POST, many tools might simply drop the body, or it might be sent to Elastic but ignored because you used GET.
When executing this query in my SENSE, I get all the documents instead of just the document matching my query, proving that the body has been ignored:
GET myIndex/_search
{
"query": {
"match": {
"zlob": true
}
}
}
This example shows that you should avoid to use GET to make requests with a body, because the result will depend on the tool you use for your rest queries.

Resources