Failed to build synonyms

I was facing the same issues when I try to setup elastic server in local and connect with the litium 8 application.

When configured the elastic server in the appsettings.json in the following way.

Preformatted text "Elasticsearch": {
      "ConnectionString": "http://localhost:9200",
      "Username": null,
      "Password": null,
      "Prefix": null,
      "Synonym": {
        "Server": "http://localhost:9210",
        "ApiKey": null
      }
    },

Then I get the following error when I search an item using elastic

2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:306) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:488) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.DocumentParser.parseObject(DocumentParser.java:505) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.DocumentParser.innerParseObject(DocumentParser.java:418) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:395) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.DocumentParser.internalParseDocument(DocumentParser.java:112) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:71) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:267) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:793) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.shard.IndexShard.applyIndexOperation(IndexShard.java:770) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.shard.IndexShard.applyIndexOperationOnPrimary(IndexShard.java:742) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.bulk.TransportShardBulkAction.executeBulkItemRequest(TransportShardBulkAction.java:267) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.bulk.TransportShardBulkAction$2.doRun(TransportShardBulkAction.java:157) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.bulk.TransportShardBulkAction.performOnPrimary(TransportShardBulkAction.java:202) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:114) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:81) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryShardReference.perform(TransportReplicationAction.java:895) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.support.replication.ReplicationOperation.execute(ReplicationOperation.java:109) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.runWithPrimaryShardReference(TransportReplicationAction.java:374) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.lambda$doRun$0(TransportReplicationAction.java:297) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:63) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.shard.IndexShard.lambda$wrapPrimaryOperationPermitListener$24(IndexShard.java:2791) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.ActionListener$3.onResponse(ActionListener.java:113) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.shard.IndexShardOperationPermits.acquire(IndexShardOperationPermits.java:285) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.shard.IndexShardOperationPermits.acquire(IndexShardOperationPermits.java:237) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.shard.IndexShard.acquirePrimaryOperationPermit(IndexShard.java:2765) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.support.replication.TransportReplicationAction.acquirePrimaryOperationPermit(TransportReplicationAction.java:836) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.doRun(TransportReplicationAction.java:293) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.action.support.replication.TransportReplicationAction.handlePrimaryRequest(TransportReplicationAction.java:256) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler$1.doRun(SecurityServerTransportInterceptor.java:257) [x-pack-security-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:315) [x-pack-security-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:63) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:762) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:692) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]",
2023-05-08 15:37:17 "at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]",
2023-05-08 15:37:17 "at java.lang.Thread.run(Thread.java:830) [?:?]",
2023-05-08 15:37:17 "Caused by: java.lang.IllegalStateException: Can't get text on a START_OBJECT at 1:2032",
2023-05-08 15:37:17 "at org.elasticsearch.common.xcontent.json.JsonXContentParser.text(JsonXContentParser.java:85) ~[elasticsearch-x-content-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.common.xcontent.support.AbstractXContentParser.textOrNull(AbstractXContentParser.java:253) ~[elasticsearch-x-content-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.TextFieldMapper.parseCreateField(TextFieldMapper.java:824) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "at org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:284) ~[elasticsearch-7.6.2.jar:7.6.2]",
2023-05-08 15:37:17 "... 40 more"] }

Also I get the following errors when I rebuild the indexes.

**// Error - 1**
2023-05-08 13:39:03.4975 [App:01] [cf405d8c7c5c70ce6b527cfe4f353023] [TRACE] [.NET ThreadPool Worker] Litium.Application.Search.Schemas.IndexSchemaConfigurationService - Status: 400 {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"failed to build synonyms"}],"type":"illegal_argument_exception","reason":"failed to build synonyms","caused_by":{"type":"illegal_argument_exception","reason":"failed to get synonyms : http://localhost:9210/api/container/6ef08236-0168-4866-9150-5d4db3638d02/96a6bf87-2d76-4a9e-88d7-6680b5572524/solr","caused_by":{"type":"null_pointer_exception","reason":null}}},"status":400} 

**// Error - 2**
2023-05-08 13:38:43.6577 [App:01] [72dec98bb3d60c7d9229c179dd787241] [ERROR] [.NET ThreadPool Worker] Litium.Application.Search.Schemas.IndexSchemaConfigurationService - Could not create index .v2.pagedocument.en-us. ServerError: 400Type: illegal_argument_exception Reason: "failed to build synonyms" CausedBy: "Type: illegal_argument_exception Reason: "failed to get synonyms : http://localhost:9210/api/container/6ef08236-0168-4866-9150-5d4db3638d02/96a6bf87-2d76-4a9e-88d7-6680b5572524/solr" CausedBy: "Type: null_pointer_exception Reason: """" 

**// Error - 3**
[TRACE] [] Litium.Search.Indexing.IndexWriterService - Status: 200 {"took":483,"errors":true,"items":[{"index":{"
{
    "took": 8,
    "errors": true,
    "items": [{
            "index": {
                "_index": ".aw.productdocument.sv-se",
                "_type": "_doc",
                "_id": "8a876cde704108e1f8e2639c9aca12ee",
                "_version": 5,
                "result": "updated",
                "_shards": {
                    "total": 2,
                    "successful": 1,
                    "failed": 0
                },
                "_seq_no": 139051,
                "_primary_term": 1,
                "status": 200
            }
        }, {
            "index": {
                "_index": ".aw.productdocument.sv-se",
                "_type": "_doc",
                "_id": "18a2e4282958ebad7ff16703c7911fdd",
                "status": 400,
                "error": {
                    "type": "mapper_parsing_exception",
                    "reason": "failed to parse field [joinField] of type [text] in document with id '18a2e4282958ebad7ff16703c7911fdd'. Preview of field's value: '{parent=8a876cde704108e1f8e2639c9aca12ee, name=child}'",
                    "caused_by": {
                        "type": "illegal_state_exception",
                        "reason": "Can't get text on a START_OBJECT at 1:1787"
                    }
                }
            }
        }, 
    ]
}

**Error - 4**
2023-05-08 15:37:17 {"type": "server", "timestamp": "2023-05-08T13:37:17,402Z", "level": "DEBUG", "component": "o.e.a.b.TransportShardBulkAction", "cluster.name": "docker-cluster", "node.name": "7af0eb73836b", "message": "[.aw.productdocument.sv-se][0] failed to execute bulk item (index) index {[.aw.productdocument.sv-se][_doc][3a0552fffc7fc83f27250c9ffe2b1a70], source[n/a, actual length: [2kb], max length: 2kb]}", "cluster.uuid": "5xib6rc5TWWQf2wqkN22vw", "node.id": "PzpRP_w6TWu0H-mCJyxfhg" , 
2023-05-08 15:37:17 "stacktrace": ["org.elasticsearch.index.mapper.MapperParsingException: failed to parse field [joinField] of type [text] in document with id '3a0552fffc7fc83f27250c9ffe2b1a70'. Preview of field's value: '{parent=231cd0b22cc277a81791e5ce4fbb0e98,
name=child}'",

I finally tried the accepted answer of this tread, It worked! :slight_smile:

All the above issues got resolved when I change the elastic ip from localhost or 127.0.0.1 to the real network ip of my machine as bellow.

   "Elasticsearch": {
      "ConnectionString": "http://**10.11.12.147**:9200",
      "Username": null,
      "Password": null,
      "Prefix": null,
      "Synonym": {
        "Server":  "http://**10.11.12.147**:9210",
        "ApiKey": null
      }
    }

I hope this helps.

*posting the junky errors to help search :upside_down_face: