elasticsearch-query

Elasticsearch match vs. term in filter

时光怂恿深爱的人放手 提交于 2020-07-09 13:11:44
问题 I don't see any difference between term and match in filter: POST /admin/_search { "query": { "bool": { "filter": [ { "term": { "partnumber": "j1knd" } } ] } } } And the result contains not exactly matched partnumbers too, e.g.: "52527.J1KND-H" Why? 回答1: Term queries are not analyzed and mean whatever you send will be used as it is to match the tokens in the inverted index, while match queries are analyzed and the same analyzer applied on the fields, which is used at index time and

Elastic Search Aggregation and Complex Query

前提是你 提交于 2020-06-29 03:38:28
问题 I have created the index PUT ten2 { "mappings": { "documents": { "properties": { "title": { "type": "text", "fields": { "raw": { "type": "keyword" } } },"uid": { "type": "text", "fields": { "raw": { "type": "keyword" } } }, "publish_details": { "type": "nested", "properties": { "environment": { "type": "keyword" }, "locale": { "type": "keyword" }, "time": { "type": "date" }, "version": { "type": "integer" } } } } } } } and added documents into it. here is the list of documents: [{ "_index":

Elasticsearch: Sort the Documents on the index value of the search string in a text field

南笙酒味 提交于 2020-06-28 05:02:14
问题 I have Elasticsearch data like this- PUT /text/_doc/1 { "name": "pdf1", "text":"For the past six weeks. The unemployment crisis has unfolded so suddenly and rapidly." } PUT /text/_doc/2 { "name": "pdf2", "text":"The unemployment crisis has unfolded so suddenly and rapidly." } In this example I am making a full text search, I am searching for all the documents that have "unemployment" sub-string in the "text" field. And in the end i want all the documents sorted in the ascending order of the

What is difference between match and bool must match query in Elasticsearch

不羁岁月 提交于 2020-05-14 01:00:26
问题 What is the difference between Only match and bool must match query in ES? First, Only use the match query { "query":{ "match":{ "address":"mill" } } } Second, use compound query { "query": { "bool": { "must": [ { "match": { "address": "mill" } } ] } } } Can you tell me everything? What is difference between them? 回答1: When you use only one match inside a bool must clause then there is no difference, the bool clause is useful when you want to combine multiple(boolean) criteria, more info on

How do I tell an ElasticSearch multi-match query that I want numeric fields, stored as strings, to return matches with numeric strings?

好久不见. 提交于 2020-04-18 03:49:34
问题 I am writing a Flask app and I am using elasticsearch. Here is search.py : from flask import current_app def query_object(index, fields, query, page, per_page, fuzziness=0): search = current_app.elasticsearch.search( index=index, body={'query': {'multi_match': {'query': str(query), 'fields': fields, 'fuzziness': fuzziness, 'lenient': True}}, 'from': (page - 1) * per_page, 'size': per_page} ) ids = [int(hit['_id']) for hit in search['hits']['hits']] return ids, search['hits']['total']['value']

How to count a number of unique documents by a nested field in Elasticsearch?

丶灬走出姿态 提交于 2020-04-16 02:28:30
问题 I'm trying to count documents with unique nested field value (and next, the documents itself also). Looks like getting the unique documents works. But when I'm trying to execute a request for count , I'm getting an error as follows: Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://localhost:9200], URI [/package/_count?ignore_throttled=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true], status line [HTTP/1.1 400 Bad Request] {"error":{

Elastic Search: Query on multiple fields

一世执手 提交于 2020-03-26 05:32:28
问题 I have JSON document in elastic search as follows { "animals": [ { "id": 1, "name": "cat" }, { "id": 2, "name": "dog" }, { "id": 3, "name": "rabbit" } ] } How to query return this document only when all the three animals are present? This is not working. curl -H 'Content-Type: application/json' -XPOST http://localhost:9200/*animals*/_search -d '{ "query": { "bool": { "must": [ { "term": { "animals.name.keyword": "dog" } }, { "term": { "animals.name.keyword": "cat" } }, { "term": { "animals

Elastic Search: Query on multiple fields

我们两清 提交于 2020-03-26 05:32:09
问题 I have JSON document in elastic search as follows { "animals": [ { "id": 1, "name": "cat" }, { "id": 2, "name": "dog" }, { "id": 3, "name": "rabbit" } ] } How to query return this document only when all the three animals are present? This is not working. curl -H 'Content-Type: application/json' -XPOST http://localhost:9200/*animals*/_search -d '{ "query": { "bool": { "must": [ { "term": { "animals.name.keyword": "dog" } }, { "term": { "animals.name.keyword": "cat" } }, { "term": { "animals

Boolean Query with Elasticsearch

流过昼夜 提交于 2020-03-25 12:31:19
问题 I am currently using the following query - { "_source": [ "title", "bench", "id_", "court", "date", "content" ], "size": 15, "from": 0, "query": { "bool": { "must": [ { "multi_match": { "query": "the", "fields": [ "content" ], "operator": "and" } }, ], "should": { "multi_match": { "query": "the", "fields": [ "content.standard^2" ], "operator": "and" } } } } , "highlight": { "pre_tags": [ "<tag1>" ], "post_tags": [ "</tag1>" ], "fields": { "content": {} }, "fragment_size": 100 } } With the

Aggregation with keywords in Elasticsearch

纵饮孤独 提交于 2020-03-21 07:00:47
问题 My end goal is to build a faceted search page using an Elasticsearch index. I am following this tutorial Why is this aggregation query not working with my data? I think I need to change my aggregation clause, so that it refers to the keywords rather than the field, but do not know the syntax. Here is my data. I mean the response to the following Postman command: GET https://<elastic username>:<elastic password>@<elastic url>:<port number>/<my index name>/_search Here's the response: { "took":