elasticserch Terms Set Query 查询 put delete

Returns any documents that match with at least one or more of the provided terms. The terms are not analyzed and thus must match exactly. The number of terms that must match varies per document and is either controlled by a minimum should match field or computed per document in a minimum should match script.

The field that controls the number of required terms that must match must be a number field:

PUT /my-index
{
    "mappings": {
        "_doc": {
            "properties": {
                "required_matches": {
                    "type": "long"
                }
            }
        }
    }
}

PUT /my-index/_doc/1?refresh
{
    "codes": ["ghi", "jkl"],
    "required_matches": 2
}

PUT /my-index/_doc/2?refresh
{
    "codes": ["def", "ghi"],
    "required_matches": 2
}

COPY AS CURLVIEW IN CONSOLE

An example that uses the minimum should match field:

GET /my-index/_search
{
    "query": {
        "terms_set": {
            "codes" : {
                "terms" : ["abc", "def", "ghi"],
                "minimum_should_match_field": "required_matches"
            }
        }
    }
}

COPY AS CURLVIEW IN CONSOLE

Response:

{
  "took": 13,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped" : 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.5753642,
    "hits": [
      {
        "_index": "my-index",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.5753642,
        "_source": {
          "codes": ["def", "ghi"],
          "required_matches": 2
        }
      }
    ]
  }
}

Scripts can also be used to control how many terms are required to match in a more dynamic way. For example a create date or a popularity field can be used as basis for the number of required terms to match.

Also the params.num_terms parameter is available in the script to indicate the number of terms that have been specified.

An example that always limits the number of required terms to match to never become larger than the number of terms specified:

GET /my-index/_search
{
    "query": {
        "terms_set": {
            "codes" : {
                "terms" : ["abc", "def", "ghi"],
                "minimum_should_match_script": {
                   "source": "Math.min(params.num_terms, doc[‘required_matches‘].value)"
                }
            }
        }
    }
}

原文地址:https://www.cnblogs.com/tingtingbai/p/9717600.html

时间: 2024-11-11 09:57:12

elasticserch Terms Set Query 查询 put delete的相关文章

delphi中用Table表组件和Query查询组件配合进行的增删改查

一.打开数据库表进入检索状态 var Table1:TTable; //定义Table1为TTable类型的变量 begin Table1:=TTable.Create(self);//自建表 Table1:=DatabaseName:='rsgl';//数据库名 Table1:=TableName:='operator.db' //打开数据库Table表 文件名是"operator.db" Table1.Open;   //Table1表开启状态 Table1.SetKey; //将

Oracle闪回查询恢复delete删除数据

Flashback query(闪回查询)原理 Oracle根据undo信息,利用undo数据,类似一致性读取方法,可以把表置于一个删除前的时间点(或SCN),从而将数据找回. Flashback query(闪回查询)前提: SQL> show parameter undo; NAME                                TYPE       VALUE ------------------------------------ ----------- --------

解决query查询输入geometry参数查询不到而通过where条件可以查到的问题

解决query查询输入geometry参数查询不到而通过where条件可以查到的问题 原因: 是因为geometry的坐标系和所要查询的图层不一样导致的(问题引起是由于底图中叠加了不同的坐标系的引起的) 问题描述: 我在公司做好的功能并且测好了,到现场出了问题,发现通过where语句查询时正常的,拉宽查询不正常.并且通过网页打开图层查询请求页面,手动输入代码中得到的geometry查询是可以查到数据的. 问题解决过程: 通过fiddler跟踪请求的http路径(因为arcgisAPI请求arcg

ArcGIS API for Javascript 使用query查询以某个点为半径的圆内的要素出现“esri.config.defaults.io.proxyUrl 尚未进行设置”错误

当使用Query查询时,会用如下配置 var queryTask = new esri.tasks.QueryTask(applicationModelOneSearchPOIURL); var query = new esri.tasks.Query(); query.geometry = geometry; query.outSpatialReference = map.spatialReference; query.spatialRelationship = esri.tasks.Quer

分享知识-快乐自己:Hibernate 中Criteria Query查询详解

1):Hibernate 中Criteria Query查询详解 当查询数据时,人们往往需要设置查询条件.在SQL或HQL语句中,查询条件常常放在where子句中. 此外,Hibernate还支持Criteria查询(Criteria Query),这种查询方式把查询条件封装为一个Criteria对象. 在实际应用中,使用Session的createCriteria()方法构建一个org.hibernate.Criteria实例,然后把具体的查询条件通过Criteria的add()方法加入到Cr

50.常用的query查询方式

主要知识点 match all match multi match range query term query terms query exist query 1.match all 查询所有 GET /_search { "query": { "match_all": {} } } 示例: GET /company/employee/_search { "query": { "match_all": {} } } 2.ma

(12)ElasticSearch 基本查询(Query查询)

1.数据准备 PUT /lib3 { "settings":{ "number_of_shards":3, "number_of_replicas":0 }, "mappings":{ "user":{ "properties":{ "name":{"type":"text"}, "address":{&qu

Mongodb query查询

Query.All("name", "a", "b");//通过多个元素来匹配数组Query.And(Query.EQ("name", "a"), Query.EQ("title", "t"));//同时满足多个条件Query.EQ("name", "a");//等于Query.Exists("type",

来自官方的Range Query查询介绍【全英文】

Matches documents with fields that have terms within a certain range. The type of the Lucene query depends on the field type, for string fields, the TermRangeQuery, while for number/date fields, the query is a NumericRangeQuery. The following example