Home > OS >  Multi Search Not Possible Within a Mapped Index?
Multi Search Not Possible Within a Mapped Index?

Time:06-28

I have the following mapping:

    {
        "hero_index": {
            "mappings": {
                "dynamic": "strict",
                "properties": {
                    "name": {
                        "type": "keyword"
                    },
                    "super_power": {
                        "type": "keyword"
                    },
                    "weakness": {
                        "type": "keyword"
                    }
                }
            }
        }
    }

All good until I want to https://localhost:9200/super_heroes/_msearch with a body that looks like:

         [
            {"query": {"term": {"name": {"term": "Hulk"}}}},
            {"index": "super_heroes"},
            {"query": {"term": {"word": {"term": "Iron Man"}}}}
    
         ]

But I get the following error...

    {
        "error": {
            "root_cause": [
                {
                    "type": "x_content_parse_exception",
                    "reason": "[1:2] Unexpected close marker ']': expected '}' (for root starting at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 0])\n at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 2]"
                }
            ],
            "type": "x_content_parse_exception",
            "reason": "[1:2] Unexpected close marker ']': expected '}' (for root starting at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 0])\n at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 2]",
            "caused_by": {
                "type": "json_parse_exception",
                "reason": "Unexpected close marker ']': expected '}' (for root starting at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 0])\n at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 2]"
            }
        },
        "status": 400
    }

I am not sure why that is or how to fix it... any ideas?

CodePudding user response:

The _msearch query accepts body in this format:

{metadata}
{query}
{metadata}
{query}

You're trying to send a JSON array, this is why you get an error.

Try this (note, first blank object is required, since you're not sending any metadata):

{ }
{"query": {"term": {"name": {"term": "Hulk"}}}},
{"index": "super_heroes"},
{"query": {"term": {"word": {"term": "Iron Man"}}}}

Source

  • Related