logo
down
shadow

Is there a way to exclude a field in an Elasticsearch query


Is there a way to exclude a field in an Elasticsearch query

Content Index :

Is there a way to exclude a field in an Elasticsearch query
Tag : elasticsearch , By : ArmHead
Date : November 29 2020, 01:01 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Tag : elasticsearch , By : sadboy
Date : March 29 2020, 07:55 AM
Hope that helps After reading the mapping document thoroughly, I finally found my mistake while creating mapping. I was creating mapping for key as follows (refer code in Question):
field("index","not_analyzed")

Exclude a field on a Elasticsearch query


Tag : elasticsearch , By : Ernie Thomason
Date : March 29 2020, 07:55 AM
Hope this helps The _source/exclude setting is only useful for not returning the body field in the response, but that doesn't exclude that field from being searched.
What you can do is to specify all the fields you want to search instead (whitelist approach)
curl -XGET 'localhost:9200/testidx/items/_search?pretty=true' -d '{
  "query" : {
     "query_string": {
          "fields": ["title", "field2", "field3"],      <-- add this
          "query": "Titulo"
     }},
     "_source" : {
          "exclude" : ["*.body"]
     }
}'
curl -XGET 'localhost:9200/testidx/items/_search?pretty=true' -d '{
  "query" : {
     "query_string": {
          "query": "Titulo AND -body:Titulo"                <-- modify this
     }},
     "_source" : {
          "exclude" : ["*.body"]
     }
}'

Exclude in elasticsearch query gives failed to parse search source. expected field name but got [START_OBJECT]


Tag : curl , By : Ivan Belov
Date : March 29 2020, 07:55 AM
This might help you I have following query, which 1. get all data with logtype error. 2. exclude all data in which there is error occured in logmessage fields. , Try this:
curl -s -XGET 'localhost:9200/index_name/type/_search?pretty=true&size=10' -d '{
  "query": {
    "bool": {
      "must": {
        "match": {
          "logtype": "error"
        }
      },
      "must_not": {
         "match": {
           "logMessage": "*error occured*"
         }
      }
    }
  }
}'

How to exclude a field from getting searched by elasticsearch 6.1?


Tag : elasticsearch , By : Chaz
Date : March 29 2020, 07:55 AM
this one helps. There is a way to make it work, it's not pretty but will do the job. You may achieve your goal using a boost and multifield parameters of query_string, bool query to combine the scores and setting min_score:
POST my-query-string/doc/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "#{query}",
            "type": "most_fields",
            "boost": 1
          }
        },
        {
          "query_string": {
            "fields": [
              "comments"
            ],
            "query": "#{query}",
            "boost": -1
          }
        }
      ]
    }
  },
  "min_score": 0.00001
}
PUT my-query-string/doc/1
{
  "title": "Prodigy in Bristol",
  "text": "Prodigy in Bristol",
  "comments": "Prodigy in Bristol"
}
PUT my-query-string/doc/2
{
  "title": "Prodigy in Birmigham",
  "text": "Prodigy in Birmigham",
  "comments": "And also in Bristol"
}
PUT my-query-string/doc/3
{
  "title": "Prodigy in Birmigham",
  "text": "Prodigy in Birmigham and Bristol",
  "comments": "And also in Cardiff"
}
PUT my-query-string/doc/4
{
  "title": "Prodigy in Birmigham",
  "text": "Prodigy in Birmigham",
  "comments": "And also in Cardiff"
}
POST my-query-string/doc/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "Bristol"
          }
        },
        {
          "query_string": {
            "fields": [
              "comments"
            ],
            "query": "Bristol",
            "boost": -1
          }
        }
      ]
    }
  }
}
{
  "hits": {
    "total": 3,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "my-query-string",
        "_type": "doc",
        "_id": "3",
        "_score": 0.2876821,
        "_source": {
          "title": "Prodigy in Birmigham",
          "text": "Prodigy in Birmigham and Bristol",
          "comments": "And also in Cardiff"
        }
      },
      {
        "_index": "my-query-string",
        "_type": "doc",
        "_id": "2",
        "_score": 0,
        "_source": {
          "title": "Prodigy in Birmigham",
          "text": "Prodigy in Birmigham",
          "comments": "And also in Bristol"
        }
      },
      {
        "_index": "my-query-string",
        "_type": "doc",
        "_id": "1",
        "_score": 0,
        "_source": {
          "title": "Prodigy in Bristol",
          "text": "Prodigy in Bristol",
          "comments": "Prodigy in Bristol",
          "discount_percent": 10
        }
      }
    ]
  }
}
POST my-query-string/doc/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "type": "most_fields",
            "query": "Bristol"
          }
        },
        {
          "query_string": {
            "fields": [
              "comments"
            ],
            "query": "Bristol",
            "boost": -1
          }
        }
      ]
    }
  }
}
{
  "hits": {
    "total": 3,
    "max_score": 0.57536423,
    "hits": [
      {
        "_index": "my-query-string",
        "_type": "doc",
        "_id": "1",
        "_score": 0.57536423,
        "_source": {
          "title": "Prodigy in Bristol",
          "text": "Prodigy in Bristol",
          "comments": "Prodigy in Bristol",
          "discount_percent": 10
        }
      },
      {
        "_index": "my-query-string",
        "_type": "doc",
        "_id": "3",
        "_score": 0.2876821,
        "_source": {
          "title": "Prodigy in Birmigham",
          "text": "Prodigy in Birmigham and Bristol",
          "comments": "And also in Cardiff"
        }
      },
      {
        "_index": "my-query-string",
        "_type": "doc",
        "_id": "2",
        "_score": 0,
        "_source": {
          "title": "Prodigy in Birmigham",
          "text": "Prodigy in Birmigham",
          "comments": "And also in Bristol"
        }
      }
    ]
  }
}
POST my-query-string/doc/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "Bristol",
            "type": "most_fields",
            "boost": 1
          }
        },
        {
          "query_string": {
            "fields": [
              "comments"
            ],
            "query": "Bristol",
            "boost": -1
          }
        }
      ]
    }
  },
  "min_score": 0.00001
}
{
  "hits": {
    "total": 2,
    "max_score": 0.57536423,
    "hits": [
      {
        "_index": "my-query-string",
        "_type": "doc",
        "_id": "1",
        "_score": 0.57536423,
        "_source": {
          "title": "Prodigy in Bristol",
          "text": "Prodigy in Bristol",
          "comments": "Prodigy in Bristol",
          "discount_percent": 10
        }
      },
      {
        "_index": "my-query-string",
        "_type": "doc",
        "_id": "3",
        "_score": 0.2876821,
        "_source": {
          "title": "Prodigy in Birmigham",
          "text": "Prodigy in Birmigham and Bristol",
          "comments": "And also in Cardiff"
        }
      }
    ]
  }
}
POST my-query-string/doc/_search
{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": {
            "query_string": {
              "fields" : ["*", "comments^0"],
              "query": "#{query}"
            }
          }
        }
      }
    }
  },
  "min_score": 0.00001
}
"fields": ["*"]

Elasticsearch exclude top hit on field value


Tag : elasticsearch , By : aspitzer
Date : March 29 2020, 07:55 AM
it fixes the issue I think you can get away with sorting by two fields in your top_hits: by active and by collected. Basically, you want trues to be first and when equal, then sort by collected. Something like the following will always show the active:true documents sorted by collected.
The only downside to this solution is that if you don't have any active documents, top_hits will show one active:false document.
{
  "size": 0,
  "aggs": {
    "group": {
      "terms": {
        "field": "country"
      },
      "aggs": {
        "group_docs": {
          "top_hits": {
            "size": 1,
            "sort": [
              {
                "active": {
                  "order": "desc"
                }, 
                "collected": {
                  "order": "desc"
                }
              }
            ]
          }
        }
      }
    }
  }
}
Related Posts Related QUESTIONS :
  • Tweaking relevance score of only certain queries
  • Nested boolean aggregation in elastic
  • Some Elastic fields DSL query searchable and some not
  • Elastic Search - search token aliasing
  • Elasticsearch : Search with special character Open & Close parentheses
  • Non indexed field in sort clause
  • Elastic search aggregation with range query ignored
  • Ship filebeat logs to logstash to index with docker metadata
  • How to get the SUM of the final score in an Elastic Search query_string request?
  • How to bypass filter if a tag is included?
  • The RestHighLevelClient cannot be used with elasticsearch 7 BulkProcessor. Which client should be used?
  • Can we use Elasticsearch SQL to insert or update data?
  • Elastic Search | How to get original search query with corresponding match value
  • Elasticsearch: getting documents with exactly a certain value in a field
  • Bucket selector in sub aggregation or cardinality aggregation
  • Elasticsearch query: range query on two fields, but one is optional field
  • use max/min aggregation on a geo_point field type
  • ElasticSearch parent/child on different indexes
  • How to update particular field in Elasticsearch index?
  • Summing nested documents in Elasticsearch
  • How to aggregate keyword field by a specific value in elasticsearch
  • How to activate and configure ElasticSearch Kafka Connect sink?
  • Making aggregations in two different types and return it grouped in Elasticsearch
  • Haystack and ElasticSearch only exact search
  • what is purpose in must nested in filter elasticsearch?
  • Opendistro elasticsearch, no permissions for [ ] and User [name=admin, roles=[admin]
  • Find empty strings in elasticsearch
  • Implementing Array.Except(Array2) > 0 query in elasticsearch filter?
  • Elasticsearch count elements in array, for a property having a value
  • Read filebeat configration from Http URL?
  • Elasticsearch match nested field against array of values
  • Elasticsearch Primary Shards not balanced
  • How to tell ElasticSearch to create nested fields
  • ElasticSearch duplicating indexes
  • Issue while querying on a field that store a file path on ElasticSearch
  • How do we bucket aggregate only on the matched prefix on Elasticsearch?
  • Elasticsearch Completion Suggester - Sort suggestions
  • elasticsearch comparison between fields
  • Could not able to use geo_ip in logstash 2.4
  • ElasticSearch nGram filters out punctuation
  • Determining which words were matched in a fuzzy search
  • ES Time series data using Percentile/median
  • Writing queries in Kibana search bar
  • elasticsearch: update in a nested object (HTTP)
  • Joda Time - String to DateTime conversion
  • Request timedout during delete/create on elasticsearch while snapshot is being taken
  • query specific fields by document type
  • Elasticsearch - combining query_string and bool query in filter
  • How to create a bool filter on multiple fields in Elasticsearch?
  • Retrieve a document from elastic search by matching two fields
  • What's the equivalent of "facet_filter" field of facets, but for aggregations?
  • Create an empty alias in ElasticSearch
  • How to really reindex data in elasticsearch
  • Elasticsearch 6 Mapping creation throwing error
  • Make all objects in elastic search nested objects
  • Issue in reading log file that contains date in it's name
  • Nesting relationship with ElasticSearch
  • Combining Attribute / Fluent Mapping for Copy_To with Nest
  • What's a difference between indexing document after creating an index mapping AND creating an document directly with ind
  • upload stopwords and synonyms to Elasticsearch could server
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com