I am using elasticsearch 2.3.3. I am trying to set up a template query using the following mustache script:
{
"from":"{{from}}",
"size":"{{size}}",
"query": {
"multi_match": {
"query": "{{query}}",
"type": "most_fields",
"fields": [ "meta.court^1.5",
"meta.judge^1.5",
"meta.suit_no^4",
"meta.party1^1.5",
"meta.party2^1.5",
"meta.subject^3",
"content"]
}
}
}
I have successfully indexed this script as follows:
POST /_search/template/myscript
{
"script":{
"from":"{{from}}"
,"size":"{{size}}"
,"query": {
"multi_match": {
"query": "{{query}}",
"type": "most_fields",
"fields": [ "meta.court^1.5", "meta.judge^1.5", "meta.suit_no^4", "meta.party1^1.5", "meta.party2^1.5", "meta.subject^3", "content"]
}
}
}
}
However when I try to render the template for example with:
GET _render/template
{
"id": "myscript",
"params":{
"from":"0"
,"size":"10"
,"query":"walter"
}
}
I get the following error:
{
"error": {
"root_cause": [
{
"type": "json_parse_exception",
"reason": "Unexpected character ('=' (code 61)): was expecting a colon to separate field name and value\n at [Source: [B#39f8927e; line: 1, column: 8]"
}
],
"type": "json_parse_exception",
"reason": "Unexpected character ('=' (code 61)): was expecting a colon to separate field name and value\n at [Source: [B#39f8927e; line: 1, column: 8]"
},
"status": 500
}
The funny thing is I can successfully execute the script if it is stored as a file in the config/scripts directory of an es node.
What am I missing here? Any help would be greatly appreciated.
Many thanks
Related
I am trying to add a new field to my already exist Elasticsearch index but I'm getting the below exception:
{
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: mapping type is missing;"
}
I'm using the below API
PUT order/_mapping
{
"properties": {
"title": { "type": "text"}
}
}
You need to add the mapping type to the PUT request, and modify the request as :
PUT order/{{mapping-type}}/_mapping
{
"properties": {
"title": { "type": "text"}
}
}
Some of my keywords contain and/or. The string query I made breaks when I use that data. My string queries need to be able to handle that data within its queries
Here is my query and error:
Query:
POST /test/_doc
{
"keyword":"pizza oven and/or pizza"
}
GET /test/_search
{
"query": {
"bool": {
"should": [
{
"query_string": {
"default_field": "keywords.english",
"query": "(pizza oven and/or pizza) OR (bread)"
}
}
]
}
}
}
Error:
{
"shard": 0,
"index": "test",
"node": "V3XGiCPAS0ej2PmYuk12qw",
"reason": {
"type": "query_shard_exception",
"reason": "Failed to parse query [(pizza oven and/or pizza) OR (bread)]",
"index_uuid": "OXSS-p_DTqeddnFkSjwWOw",
"index": "test",
"caused_by": {
"type": "parse_exception",
"reason": "parse_exception: Cannot parse '(pizza oven and/or pizza) OR (bread)': Lexical error at line 1, column 37. Encountered: <EOF> after : \"/or pizza) OR (bread)\"",
"caused_by": {
"type": "token_mgr_error",
"reason": "token_mgr_error: Lexical error at line 1, column 37. Encountered: <EOF> after : \"/or pizza) OR (bread)\""
}
}
}
}
How can I make that the and/or doesn't break the string query?
The / is a reserved character in the query string query language, you need to escape it:
"query": "(pizza oven and\/or pizza) OR (bread)"
^
|
I am trying out the new elasticsearch feature elasticsearch sql with elasticsearch 6.3.0
I have a question that it seems not able to query an object in an array with this sql feature.
for example I have indexed a doc as below:
PUT /test/_doc/1
{
"orderId": "123456",
"items": [
{
"itemId": "1234",
"name": "ipad"
}
]
}
and I try an query:
POST /_xpack/sql?format=txt
{
"query": "select items.itemId from test"
}
it gives me error as below:
{
"error": {
"root_cause": [
{
"type": "sql_illegal_argument_exception",
"reason": "Cannot extract value [items.itemId] from source"
}
],
"type": "sql_illegal_argument_exception",
"reason": "Cannot extract value [items.itemId] from source"
},
"status": 500
}
may I know is there a way to query the data in objects of an array?
For example, how would you build an Elasticsearch query that filtered by documents containing an ip field that matches 192.168.100.14/24?
{
query: {
filtered: {
filter: {
???
}
}
}
}
To clarify, the documents I am searching have a property that is indexed as an IP field, and I want to find all documents that have an IP that matches a CIDR mask (to be specified in a filter).
try this if using ES 2.2 or later:
{"query": {"term" : {"<ip_field_name>" : "192.168.100.14/24"}}}
The elasticsearch type ip does not support that type of input. Here is an example showing that it will fail:
input
PUT index1
{
"mappings": {
"type1": {
"properties": {
"ip_addr": {
"type": "ip"
}
}
}
}
}
POST index1/type1
{
ip_addr: "192.168.100.14/24"
}
result
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse [ip_addr]"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse [ip_addr]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "failed to parse ip [192.168.100.14/24], not a valid ip address"
}
},
"status": 400
}
Instead, if you strip off the /24 it will work properly.
I have a index in Elasticsearch, and want to update the type of a field named currentTimeStamp from long to date, so that Kibana can work on it. Following is my current output of _mapping (Other fields have been removed for brevity).
{
"myIndexname": {
"mappings": {
"myType": {
"properties": {
"currentTimeStamp": {
"type": "long"
}
}
}
}
}
}
When I try to run the following command for updating the type of the column to date type, I get the below mentioned error response. Any help on this is highly appreciated.
curl -X PUT myIndexname/_mapping/myType with the following payload
{
"myIndexname": {
"properties": {
"currentTimeStamp": {
"type": "date",
"format": "date_optional_time || epoch_millis"
}
}
}
}
Error response:
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [optimizationframework : {properties={currentTimeStamp={type=date, format=date_optional_time || epoch_millis}}}]"
}
],
"type": "mapper_parsing_exception",
"reason": "Root mapping definition has unsupported parameters: [optimizationframework : {properties={currentTimeStamp={type=date, format=date_optional_time || epoch_millis}}}]"
},
"status": 400
}