Match query doesn't return the result - elasticsearch

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

Related

Get document by index position in Elasticsearch

I am working with Elasticsearch and I am getting a query error:
elasticsearch.exceptions.TransportError: TransportError(500, 'search_phase_execution_exception', 'script score query returned an invalid score: NaN for doc: 32894')
It seems like my metric is returning NaN for document 32894 (NaN for doc: 32894). Naturally, the next step is to look at that document to see if there is anything wrong with it.
The problem is that I upload my documents using my own ID, so "32894" is meaningless for me.
A query like
curl -X GET "localhost:9200/my_index/_doc/one_of_my_ids?pretty&pretty"
works fine, but this fails if I try with the doc number from the error message.
I expected this to be trivial, but some Google has failed to help.
How can I then find this document? Or is using my own IDs not recommended and the unfixable source of this problem?
Edit: as requested, this is the query that fails. Note that obviously fixing this is my ultimate goal, but not the specific point of this question. Help appreciated in either case.
I am using the elasticsearch library in Python.
self.es.search(index=my_index, body=query_body, size=number_results)
With
query_body = {
"query": {
"script_score": {
"query": {"match_all": {}},
"script": {
"source": "cosineSimilaritySparse(params.queryVector, doc['embedding']) + 10.0",
"params": {"queryVector": query_vector}
}
}
}
}

ElasticSearch - Delete documents by specific field

This seemingly simple task is not well-documented in the ElasticSearch documentation:
We have an ElasticSearch instance with an index that has a field in it called sourceId. What API call would I make to first, GET all documents with 100 in the sourceId field (to verify the results before deletion) and then to DELETE same documents?
You probably need to make two API calls here. First to view the count of documents, second one to perform the deletion.
Query would be the same, however the end points are different. Also I'm assuming the sourceId would be of type keyword
Query to Verify
POST <your_index_name>/_search
{
"size": 0,
"query": {
"term": {
"sourceId": "100"
}
}
}
Execute the above Term Query and take a note at the hits.total of the response.
Remove the "size":0 in the above query if you want to view the entire documents as response.
Once you have the details, you can go ahead and perform the deletion using the same query as shown in the below query, notice the endpoint though.
Query to Delete
POST <your_index_name>/_delete_by_query
{
"query": {
"term": {
"sourceId": "100"
}
}
}
Once you execute the Deletion By Query, notice the deleted field in the response. It must show you the same number.
I've used term queries however you can also make use of any Match or any complex Bool Query. Just make sure that the query is correct.
Hope it helps!
POST /my_index/_delete_by_query?conflicts=proceed&pretty
{
"query": {
"match_all": {}
}
}
Delete all the documents of an index without deleting the mapping and settings:
See: https://opster.com/guides/elasticsearch/search-apis/elasticsearch-delete-by-query/

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.

Is there a way to deliberately return a null value with an Elasticsearch query?

I have to return an elasticsearch query in my code (Golang using olivere's elastic v.5 library) and if a particular condition occurs, I want to be able to pass in a query that will take minimal time and always return null. Is there a standard way to do this? I tried using a Term query with empty strings as parameters:
elastic.NewTermQuery("", "")
But this doesn't seem to be a valid query. Is there a good way to do this?
If by "always return null" you mean match nothing:
{
"bool": {
"must_not": {
"match_all": {}
}
}
}
I'm sure match_all is implemented very efficiently.

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 .

Resources