简体   繁体   English

有没有办法查看查询是否与Elasticsearch中的数组中的任何元素匹配?

[英]Is there a way to see if a query matches any element in an array in Elasticsearch?

I have this query (eg 'hello') and this id (eg '12345') and I want to search for something that matches both the query in a 'text' field and the id in a 'thread' field. 我有这个查询(例如“ hello”)和这个ID(例如“ 12345”),我想搜索与“文本”字段中的查询和“线程”字段中的ID都匹配的内容。 But the given ids are in an array, so the logic is something like: 但是给定的id在数组中,因此逻辑类似于:

function runThisQuery(query, ids) {
    client.search({        
    index: '_all',
    type: 'text',
    body: {
      query: {
        bool: {
          must: { 
            match: { text: query } 
          }, 
          should: [
            { match: { thread: { query: ids[0], operator: 'AND'} } },
            { match: { thread: { query: ids[1], operator: 'AND'} } }
          ],
          minimum_should_match: 1
        }
      }
    }
  })
}

Is there like an $in operator (like in MongoDB) that matches the thread if it's in the 'ids' array? 如果线程在'ids'数组中,是否有匹配线程的$ in运算符(例如在MongoDB中)? Thanks! 谢谢!

You can use an ids query like this 您可以像这样使用ids查询

{
  "filter": {
    "ids": {
      "type": "my_type",
      "values": [
        "12345","67891","12346"
      ]
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有什么方法可以将JSON查询转换为Elasticsearch Nest搜索查询吗? - Is there any way to convert JSON query to Elasticsearch Nest search query? 还有其他方法可以针对JSON中的多个嵌套字段优化此Elasticsearch查询 - Is there any another way to optimize this elasticsearch query for multiple nested fields in JSON elasticsearch请求数组中的元素 - elasticsearch request an element in an array 如何索引Elasticsearch中的元素数组? - How to index an array of element in Elasticsearch? Elasticsearch-查询数组以匹配数组中的多个对象 - Elasticsearch - Query on array for matching multiple objects in the array 嵌套数组元素的Elasticsearch查询策略 - Elasticsearch query strategy for nested array elements MongoDB查询字符串数组以查看是否包含关键字 - Mongodb query string array to see if contains keyword 对于Boost.Propertytree,是否可以使用JSON点表示法引用数组元素? - For a Boost.Propertytree, is there any way to use JSON dot notation to reference an array element? 检查JSON数组中的任何元素是否包含特定ID的最有效方法? - Most efficient way to check if any element in a JSON array contains a specific id? 如何检查对象的值是否与 Angular 中数组列表中的任何值匹配 - How to Check If a Value of Objects Matches Any Value in a List of Array in Angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM