I am executing the following requests in elastic search through Chrome sense plugin:
DELETE /state
PUT /state
PUT /state/mapping/_mapping
{
"state" : {
"index_analyzer" : "angram",
"search_analyzer" : "standard",
"properties" : {
"stateName": {
"type" : "multi_field",
"fields": {
"stateName":{
"type":"string"
},
"untouched":{
"type" : "string","index" :"not_analyzed"
}
}
},
"countryName":
{
"type" : "multi_field",
"fields": {
"countryName":{
"type":"string"
},
"untouched":{
"type" : "string","index" :"not_analyzed"
}
}
}
}
}
}
DELETE /_river/state
PUT /_river/state/_meta
{
"type": "mongodb",
"mongodb": {
"db": "rakeshdb",
"collection": "state"
},
"index": {
"name": "state",
"type": "mapping"
}
}
I have to execute each DELETE and PUT request separately. Is there anyway to execute the complete script in a single shot.
No, the only thing you can do is merge the index creation with the put mapping call into a single create index call that contains the mappings too.
But you cannot delete an index and create one (even if another one) on the same request.
Related
I am trying to write an elastic-search query that should list all distinct values held by various fields in a document.When the fields are of type Keyword,the term aggregate query works fine and I can see the values with their counts listed in the buckets.But, I don't get any result when I query for the distinct citrus fruit types, the mapping is as shown below:
{
"vegetables":{
"type": "text",
"fields": {
"keyword" : {
"type" : "keyword",
"ignore_above": 256
}
}
},
"fruits": {
"properties": {
"citrus": {
"properties": {
"orange": {
"type": "long"
},
"lemon": {
"type": "long"
},
"kiwi": {
"type": "long"
}
}
}
}
}
}
and the result I am expecting is :
"aggregations": {
"distinct_citrusy_fruits"{
"buckets" : [
{
"key":"oranges",
"doc_count": 23
},
{
"key":"lemon",
"doc_count": 21
},
{
"key":"kiwi",
"doc_count": 23
}
]
}
}
when I make a term aggregation for the "vegetables" field (which is a keyword type) i am able to get the buckets as above.
How to get the distinct counts in this case?Also, I don't have the option to change the document format.
EDIT- the only workaround I have found till now is to call the mappings api and then parse the nested JSON in my code to get the key values,if there is any better solution possible, please add an answer here.
I think you cannot query or run aggregations on the field names, only on values.
For the fruits i expect the following mapping:
{
"fruits": {
"properties": {
"citrus": {
"properties": {
"kind": {
"type": "keyword"
},
"count": {
"type": "long"
}
}
}
}
}
}
Maybe you can use the _field_names field which contains every fieldname that has a value. (https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-field-names-field.html)
I need to make an api for stepfunctions but the problem is, how do I get the output of the first as input for the next?
Here is what I have so far:
{
"Comment": "Match",
"StartAt": "Search",
"States": {
"Search": {
"Type": "Task",
"Resource": "arn:aws:states:::ecs:runTask.sync",
"Parameters": {
"Cluster": "Search-cluster",
"TaskDefinition": "Search-task",
"Overrides": {
"ContainerOverrides": [
{
"Name": "search",
"Command.$": "$.commands"
}
]
}
},
"Next": "Save"
},
"Save": {
"Type": "Task",
"Resource": "arn:aws:states:::ecs:runTask.sync",
"Parameters": {
"Cluster": "save-cluster",
"TaskDefinition": "save-task",
"Overrides": {
"ContainerOverrides": [
{
"Name": "save",
"Command.$": "$.commands"
}
]
}
},
"Next": "Send"
},
"Send": {
"Type": "Task",
"Resource": "arn:aws:states:::ecs:runTask.sync",
"Parameters": {
"Cluster": "send-cluster",
"TaskDefinition": "send-task",
"Overrides": {
"ContainerOverrides": [
{
"Name": "send",
"Command.$": "$.commands"
}
]
}
},
"End": true
}
}
}
I was facing the same issue and contacted AWS Support. Was told that it is not possible to directly return the result of a Fargate Task like you can do with Lambdas. One of the options is to store the result of your task in a separate DB like DynamoDB and write a Lambda to retrieve the value and update your input JSON with the output from the previous task.
Sidenote: In your ASL, you should look at using ResultPath. The default behaviour is to replace the input node with the output (result). Meaning, if in your input JSON you have values that you would like to use in subsequent states and if you don't specify ResultPath, they'd be lost after the first state. Ref: https://docs.aws.amazon.com/step-functions/latest/dg/input-output-resultpath.html#input-output-resultpath-amend
You don't have to manually mange this. Lambda function's event parameter contains the previous function(s) return output(s).
I am trying to fetch records from elasticsearch using wildcard queries.
Please find the below query
get my_index12/_search
{
"query": {
"wildcard": {
"code.keyword": {
"value": "*ARG*"
}
}
}
}
It's working and giving expected results for the above query., but it is not working for the lower case value.
get my_index12/_search
{
"query": {
"wildcard": {
"code.keyword": {
"value": "*Arg*"
}
}
}
}
Try Following:
Mapping:
PUT my_index12
{
"settings": {
"analysis": {
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"char_filter": [
"html_strip"
],
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"doc": {
"properties": {
"code": {
"type": "text",
"analyzer": "custom_analyzer"
}
}
}
}
}
Then Run Query String Query
GET my_index12/_search
{
"query": {
"query_string": {
"default_field": "code",
"query": "AB\\-7000*"
}
}
}
It will also work for ab-7000*
Let me know if it works for you.
You have to normalize your keyword field:
ElasticSearch normalizer
Something like (from documentation):
PUT index
{
"settings": {
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"char_filter": [],
"filter": ["lowercase", "asciifolding"]
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"foo": {
"type": "keyword",
"normalizer": "my_normalizer"
}
}
}
}
}
UPDATE
Some additional info:
Only parts of the analysis chain that operate at the character level are applied. So for instance, if the analyzer performs both lowercasing and stemming, only the lowercasing will be applied: it would be wrong to perform stemming on a word that is missing some of its letters.
By setting analyze_wildcard to true, queries that end with a * will be analyzed and a boolean query will be built out of the different tokens, by ensuring exact matches on the first N-1 tokens, and prefix match on the last token.
I was trying to search the following case
I want to search a name that ends with the particular word. For example:
name : group Test
name : group test
name : group test org
Here is my wild card query
"bool" : {
"must" : [
{
"wildcard" : {
"name.keyword"" : {
"wildcard" : "*test",
"boost" : 1.0
}
}
}
]
}
It returns me "group test" for case sensitive search
But I need to get both "group Test" and "group test" for case-insensitive search.
my mapping as follows:
"name":{
"type":"text",
"fielddata":true
"fields":{
"keyword":{
"type":"keyword"
}
}
}
Can anyone help me to find out queries in elasticsearch java api or any other way to search it.
Elastic search version 6.1.2
Any help is really appreciated.
Unfortunately there is no direct way to do this with ES configuration as keyword type does not have the analyzer property but I found a workaround. Please take a look on this solution:
PUT test
{
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [ "lowercase", "asciifolding" ]
}
},
"normalizer": {
"lowerasciinormalizer": {
"type": "custom",
"filter": [ "lowercase", "asciifolding" ]
}
}
}
},
"mappings": {
"_default_": {
"dynamic_templates": [
{
"string_as_keyword": {
"match_mapping_type": "string",
"match": "*_k",
"mapping": {
"type": "keyword",
"normalizer": "lowerasciinormalizer"
}
}
}
]
}
}
}
PUT test/1/123
{
"str_k" : "string âgáÈÒU is cool"
}
GET test/_search
{
"query": {
"wildcard": {
"str_k": "*agaeou*"
}
}
}
I am unable to get swagger-codegen to generate classes for json schemas defined in files separate from the main API definition file. The command I am using is:
$ java -jar swagger-codegen-cli-2.2.2.jar generate -i api.json -l java -o gen -v
This is what api.json looks like:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Simple API",
"description": "A simple API to learn how to write OpenAPI Specification"
},
"schemes": [
"https"
],
"host": "simple.api",
"basePath": "/openapi101",
"paths": {
"/persons": {
"get": {
"summary": "Gets some persons",
"description": "Returns a list containing all persons.",
"responses": {
"200": {
"description": "A list of Person",
"schema": {
"$ref" : "person.json#/definitions/person"
}
}
}
}
}
}
}
The person.json file referenced here lives alongside api.json (i.e. at the same level) and contains the following:
{"definitions": {
“person”: {
"type": "object",
"description": "",
"properties": {
"requestId": {
"type": "string",
"example": "1234"
}
}
}}}
I would expect the code generation to generate a class called Person.java - but it does not - in fact it does not generate any model classes. Also the verbose logging logs the following right at the start which makes me think it is interpreting the reference incorrectly and for some reason prepending a #definitions to the $ref.
[main] INFO io.swagger.parser.Swagger20Parser - reading from api.json
{
"swagger" : "2.0",
"info" : {
"description" : "A simple API to learn how to write OpenAPI Specification",
"version" : "1.0.0",
"title" : "Simple API"
},
"host" : "simple.api",
"basePath" : "/openapi101",
"schemes" : [ "https" ],
"paths" : {
"/persons" : {
"get" : {
"summary" : "Gets some persons",
"description" : "Returns a list containing all persons.",
"parameters" : [ ],
"responses" : {
"200" : {
"description" : "A list of Person",
"schema" : {
"$ref" : "#/definitions/person.json#/definitions/person"
}
}
}
}
}
}
}
Anybody know what is going on here and what is the correct way to reference a schema definition that lives in a local file?
Adding a ./ to the $ref makes it work.
./person.json#/definitions/person