0

I am using the following search:

{
    "_source": [
        "title",
        "bench",
        "court",
        "id_"
    ],
    "size": 10,
    "query": {

        "bool": {
            "must": {

                    "multi_match": {
                        "query": "murder" 
                    ,
                    "fields": [
                        "title",
                        "content"
                    ]
                }
            },

            "should": {
                "multi_match": {
                    "query": "murder",
                    "fields": [
                        "title.standard",
                        "content.standard"
                    ]
                }
            }

        }


    },
    "highlight": {
        "fields": {
            "title": {},
            "content": {}
        }
    }
}

I now want to filter the results using the id (_id) elastic search gave it during indexing. For example, {"_id" : 5903}. I guess you have to use the term query. The results should be such that only if the _id is matched, the document returns. How can I do that?

ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
Shawn
  • 261
  • 1
  • 7
  • 25
  • 1
    Is https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-ids-query.html what you are looking for? – ibexit Feb 08 '20 at 10:50
  • Yes. Thanks a lot! – Shawn Feb 08 '20 at 12:26
  • Cool, for all the people haveing the same need, I've created the answer in order to mark this question as solved. Please feel free to resolve it by accepting the answer. Have fun! – ibexit Feb 08 '20 at 12:37

1 Answers1

1

In order to get your query filtered by doc's id (one, or many), there is a special id query in elasticsearch. Here are the details: https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-ids-query.html

ibexit
  • 3,465
  • 1
  • 11
  • 25