Elasticsearch query on other ID field - exception

how to get match field with a string that contains "_id" in its field name.
like so:
{"query": "match" : {"extra_id": "1111_222"} }
it shows me "number_format_exception" error.
But when I change field name to something like "extra" it works fine.
This is my complete request body:
GET /latest/extra_data/_search?size=2000
{
"query": {
"match": {
"extra_id": "55502323230_81015572923293301509"
}
}
}

Related

Like expression in JSON Path

I have a JOSN some thing like this
{
"Room" :{
"Book" :
{
"name" : "abc"
},
"Book1":
{
"name" : "xyz"
},
"Book3":
{
"name" : "abc123"
},
"Tv" :
{
"name" : "zyc"
},
"audio":
{
"name" :"sound ++"
}
}
}
From this JSON I want to filter out all book elements("book","book1","book2") using JSONPATH
As I got to know in in JSONPATH we do not have any "Like" type syntax , but we can do that by using regex.
I tried with this
$.Room[?(/^.*book.*$/i.test(#.Room))]
But this expression return nothing from the JSON.
Can any one help me out in this...
Maybe this link will be helpful for you . Check the table
$..book[?(#.author =~ /.*Tolkien/i)]. This expression brings All books whose author name ends with Tolkien (case-insensitive) --> Modify it for yours

Formatting SOLR response

I have a query returning following, which is standard output of SOLR.
{
Company : "Nokia"
Series : "X"
Products : ["3320", "1100"]
ProductStatus : ["Continued","Discontinued"]
}
I want to format the output as follows
{
Company : "Nokia"
Series : "X"
Products : [{
"name": "3320",
"Status":"Continued"
},
{
"name":"1100",
"Status":"Discontinued"
}]
}
How to achieve above?

wildcards for elasticsearch simple_query_string?

As a result of the following query to the type:
"query": {
"simple_query_string" : {
"query" : "RUDVRUMMXXX"
}
}
I get 5 hits. RUDVRUMMXXX is the entire text value of some field.
When I try to search with just a bit of its value (e.x. VRUMMXXX, or VRUMMX) elastic finds nothing.
I tried to add wildcard like that:
"query": {
"simple_query_string" : {
"query" : "*VRUMMXXX",
"analyze_wildcard" : true
}
}
but get zero result anyway.
also tried this:
"query": {
"wildcard" : {
"query" : "*VRUMMXXX"
}
}
...same success.
Any help is appreciated.
Try this:
{
"query":
{
"query_string" :
{
"query" : "*VRUMMXXX"
}
}
}

Elasticsearch update mapping using json

I want to change the type of a field from 'string' to 'date' (format: 'epoch_second' to be specific). Since there is no way to update the mappings of an existing index, I need to make a new index for which I mostly want to use the mapping from my existing index. Here is what I am using:
curl -XGET 'http://localhost:9200/sam/saga/_mapping?pretty' >saga.json
to dump the mapping of the current index into a json file, the content of which is this:
{
"sam" : {
"mappings" : {
"saga" : {
"properties" : {
"name" : {
"type" : "long"
}
}
}
}
}
}
then I replace
"name" : {
"type" : "long"
}
with
"name" : {
"type" : "date"
}
and save the new file as saga2.json. then run this
curl -XPUT 'http://localhost:9200/sam/_mapping/saga2' -d #saga2.json
However, when I check the mapping of the new index, all types have changed to "string" now.
I even have this problem using the Elasticsearch's example.
Does anyone know what is wrong?
You need to make one more change in your saga2.json file, namely the mapping type name saga -> saga2 (Now you probably need to rename it all to saga3
{
"sam" : {
"mappings" : {
"saga2" : { <--- here
"properties" : {
"name" : {
"type" : "date" <--- and here
}
}
}
}
}
}
Then only you can run this:
curl -XPUT 'http://localhost:9200/sam/_mapping/saga2' -d #saga2.json

How to create an index with integer fields in Elasticsearch for the JSON file of format?

I am trying to create an index in Elasticsearch for the JSON file of format:
{ "index" : { "_index" : "entity", "_type" : "type1", "_id" : "0" } }
{ "eid":"guid of Event autogenerated", "entityInfo": { "entityType":"qualityevent", "defaultLocale":"en-US" }, "systemInfo": { "tenantId":"67" }, "attributesInfo" : { "jobId":"21", "matchStatus": "new" } }
{ "index" : { "_index" : "entity", "_type" : "type1", "_id" : "1" } }
{ "eid":"guid of Event autogenerated", "entityInfo": { "entityType":"qualityevent", "defaultLocale":"en-US" }, "systemInfo": { "tenantId":"67" }, "attributesInfo" : { "jobId":"20", "matchStatus": "existing" } }
I want the fields jobId and tenantId to be integers.
I am giving the following mapping in curl command:
curl -XPUT http://localhost:9200/entity -d '
{
"mappings": {
"entityInfo":
{
"properties" : {
"entityType" : { "type":"string","index" : "not_analyzed"},
"defaultLocale":{ "type":"string","index" : "not_analyzed"}
}
},
"systemInfo":
{
"properties" : {
"tenantId": { "type" : "integer" }
}
},
"attributesInfo" :
{
"properties" : {
"jobId": { "type" : "integer" },
"matchStatus": { "type":"string","index" : "not_analyzed"}
}
}
}
}
';
This does not give me an error. However, it creates new empty fields jobId and tenantId as integers and it keeps the existing data into attributesInfo.jobId as string. Same is the case with systemInfo.tenantId. I want to use these two fields in Kibana for visualization. I currently cannot use them as they are empty.
I am new to Kibana and Elasticsearch so I am not sure if the mapping is correct.
I have tried couple of other mappings as well but they give errors. Above mapping does not give error.
This is how Discover Tab on Kibana looks like: 1
Please let me know where I am going wrong.
I tried as you mentioned but it didn't help. What I realised after a lot of trial and error that my mapping was incorrect. I finally wrote the correct mapping and now it works correctly. Jobid and TenantId are recognised as numbers by Kibana. I am new to JSON, kibana, Bulk, Elastic so it took time to understand how mapping works.